Posts

Post not yet marked as solved
1 Replies
4.9k Views
After updating XCode to version 11 I added a new model version to Core Data and in new version I added a new attribute to an Entity. Made the new version active and added the new property to managed object file.After releasing this version to the users it started to crash with the following message: "The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store." and "duplicate column name ZNEWCOLUMN". Until now I made a lot of changes to the Core Data model and migration always worked.This crash appears only on iOS 13!This is how I load Core Data: lazy var managedObjectContext: NSManagedObjectContext = { return self.persistentContainer.viewContext }() private lazy var persistentContainer: NSPersistentContainer = { /* The persistent container for the application. This implementation creates and returns a container, having loaded 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. */ let container = NSPersistentContainer(name: "MyModel") container.persistentStoreDescriptions.append(storeDescription) container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { /* Typical reasons for an error here include: * The parent directory does not exist, cannot be created, or disallows writing. * The persistent store is not accessible, due to permissions or data protection when the device is locked. * The device is out of space. * The store could not be migrated to the current model version. Check the error message to determine what the actual problem was. */ fatalError("Unresolved error \(error), \(error.userInfo)") } }) return container }() private lazy var storeDescription: NSPersistentStoreDescription = { let storeDescription = NSPersistentStoreDescription() storeDescription.shouldMigrateStoreAutomatically = true storeDescription.shouldInferMappingModelAutomatically = true return storeDescription }()
Posted Last updated
.