0
votes

I am trying to use automatic lightweight migration in my app. I did the following steps:

  1. Create new model version.
  2. Edit new model version.
  3. Set the options NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption to YES upon creation of the persistentStoreCoordinator.
  4. 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.

2
Did you add a new model to be used as the new model, You should add a new version to your existing model. - rckoenes
@rckoenes Yes, through Editor->Add Model Version in Xcode. - jcm

2 Answers

0
votes

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.

0
votes

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

  1. delete the unused xcdatamodel.
  2. delete the database file.
  3. version the remaining model.