Core Data Migration

Hello,

I’ve been struggling with Core Data lightweight migration since the iOS 17 launch.

I have a NSPersistentStoreCoordinator which I use the following options in it:

[NSMigratePersistentStoresAutomaticallyOption: true as AnyObject, NSInferMappingModelAutomaticallyOption: true as AnyObject, NSSQLitePragmasOption: ["journal_mode": "DELETE"] as AnyObject]

I don’t create new versions when I change my .xcdatamodel. However, lightweight migration worked normally until iOS 17. And there is something else, the migration doesn’t fail for all users.

So, if I update my xcdatamodel from version 1 to 2, some users get the following error: An error occurred during persistent store migration., reason: Failed to open the store, underlyingReason: The model used to open the store is incompatible with the one used to create the store

Last but not least, my NSPersistentStoreCoordinator’s MOM merges two other models. But these two other models did not have any changes since I started getting this issue.

I don’t think the issue is because we are adding new entities or properties in our xcdatamodel because if it were, it would be described in the error we are printing when trying to add the persistent store.

I wonder if something has changed in iOS 17 that is causing this issue, which was working normally before. Also, what do you think I should do to fix this issue?

  • Versioning my xcdatamodel? Although I don’t see it as a requirement in Apple’s docs.
  • Removing the two other models from NSPersistentStoreCoordinator?
  • Something else?

More info: The issue happened when I added an attribute in an entity. And also happened when adding an entity to the same model.

The code I'm using to add the persistent store is:

try persistentCoordinator.addPersistentStore(ofType: NSInMemoryStoreType, configurationName: "InMemoryStore", at: nil, options: myOptions) try persistentCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: "PersistentStore", at: myGroupURL, options: myOptions)

In case it fails, I delete the DB and recreate it.

Core Data Migration
 
 
Q