0

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.

Breno Gazzola
  • 2,092
  • 1
  • 16
  • 36
Blamdarot
  • 3,317
  • 1
  • 18
  • 15

2 Answers2

2

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.

Breno Gazzola
  • 2,092
  • 1
  • 16
  • 36
  • How does one "look at [the] older generated model files"? – Blamdarot Sep 25 '12 at 17:42
  • You create generated model files when you click an Entity in your xcdatamodel and then select "Editor -> Create NSManagedObject subclass". If you are using version control (Xcode has integration with GIT) you can grab an older copy of it from there. If not, you can try looking for it in your Time Machine (if you have that activated on your Mac). Failing all that, you said in your original post "I managed to lose all previous versions of my xcdatamodel". Wherever you had those versions of the xcdatamodel, you should have the previous versions of yout generated model files. – Breno Gazzola Sep 25 '12 at 19:20
0

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.

Community
  • 1
  • 1
Amy Worrall
  • 16,250
  • 3
  • 42
  • 65