Попытка обновить мою DBModel с облегченной миграцией, но ничего не происходит - PullRequest
0 голосов
/ 27 августа 2018

Итак, категории из моей модели БД были обновлены (раньше было 4, теперь их 7), и я хочу обновить основные данные, а также новые объекты.

Я пытался применить это: https://developer.apple.com/documentation/coredata/using_lightweight_migration

    lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
    // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
    // Create the coordinator and store
    let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
    let url = self.applicationDocumentsDirectory.appendingPathComponent("x.sqlite")
    let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
    var failureReason = "There was an error creating or loading the application's saved data."
    do {
        try coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: options)
    } catch {
        // Report any error we got.}

Но мои данные такие же ... они не обновляются с новыми категориями. Любая помощь ? Спасибо.. PS: Должен ли я сделать новую модель и сопоставить старую модель с новой? enter image description here

Ответы [ 2 ]

0 голосов
/ 27 августа 2018

Вам необходимо создать модель базы данных CORE DATABASE. Вы можете выполнить шаги по созданию версий базы данных.

0 голосов
/ 27 августа 2018

Вы просто забыли добавить другую модель, вы не можете выполнить миграцию между моделями, если у вас есть только одна. Просто выберите ваш xcdatamodel, затем откройте Editor -> add Model Версия затем перейдите в File Inspector и выберите новый xcdatamodel в качестве текущего, затем вы получите результат. Удачи, дорогой друг

...