CoreData Automatic Lightweight Migration Error
I am trying to use automatic lightweight migration in my app. I did the following steps:
- Create new model version.
- Edit new model version.
- Set the options NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption to YES upon creation of the persistentStoreCoordinator.
- Setting the current version to the new version.
and got an error: reason = "Can't find model for source store"
I've tried Product->Clean to no avail.开发者_高级运维 Ideas?
Edit: I forgot to put in the model details.
I have two .xcdatamodel files. The first has two Entities, Event and Venue. The second has one Entity, EventDate. I no longer use the second .xcdatamodel in code but I did leave the file in the project. I am trying to add a new entity Update to the first model file.
The error ""Can't find model for source store" means that the .xcdatamodel file originally used to create the existing persistent store cannot be found.
Supposed you started with these two model files (the version number is the version of the app not the data model):
oneEntityModelv1.xcdatamodel
twoEntityModelv1.xcdatamodel
… and you want to migrate to this data model:
threeEntityModelv2.xcdatamodel
The v2 version of your app would have to include all three files for the migration to take place.
The problem was that we were using the mergedModelFromBundles to instantiate our model. Apparently that doesn't play well with automatic lightweight migration. The fix was to
- delete the unused xcdatamodel.
- delete the database file.
- version the remaining model.
精彩评论