Reputation: 3317
I am maintaining an app that has been live on the AppStore for a few months. My app uses Core Data and somehow I managed to lose all previous versions of my xcdatamodel.
I am hoping to perform a lightweight migration. All I need to do is add one attribute to one of my entities. So, I have followed the correct steps of creating a model version.
Apparently, I modified the original xcdatamodel. So, when I test the migration, it fails with an error Code=134130 "Can't find model for source store". Since the app runs fine when there is no sqlite file on the device/simulator, I've concluded that the original xcdatamodel has been modified.
Assuming my logic thus far holds, how can I create an xcdatamodel that will match the sqlite files on my users' devices. It's not acceptable for them to lose their data.
Thank you.
Upvotes: 0
Views: 1886
Reputation: 2170
According to Apple's Core Data versioning guidelines, two versions of Core Data are treated as being identifical if:
For each entity the following attributes must be equal: name, parent, isAbstract, and properties. className, userInfo, and validation predicates are not compared.
For each property in each entity, the following attributes must be equal: name, isOptional, isTransient, isReadOnly, for attributes attributeType, and for relationships destinationEntity, minCount, maxCount, deleteRule, and inverseRelationship.
If your current xcdatamodel is a completely new file, I don't think that anything you do will make the original and the current version match. However, if the current version is simply the original one accidentaly modified, you can take a look at your older generated model files and try to figure out what changed.
E.g.: on the model you had a "NSString *age" property, but on your current xcdatamodel, the property is "NSNumber *age".
Also, remember that the error you are seeing can be caused by generated model files that are out of sync with the DB, so try to recreate them.
Upvotes: 2
Reputation: 16337
With a Core Data model file open (eg a blank one), choose Editor -> Import
, and then find the .mom
file from the previous version of your app.
See this answer.
Upvotes: 0