I know that if you change the Core Data model and you have run the app before on the old model that you will get Persistent Store error. How would you handle changes to the Core Data model so you do not get this error? Is there a way to upgrade an old model so that the already saved data is not lost?
Asked
Active
Viewed 6,468 times
4
-
I have posted my answer here: http://stackoverflow.com/questions/10374027/changing-coredata-model-retro-compatibility/17110350#17110350 Hope it helps. – user1140780 Jun 14 '13 at 14:04
2 Answers
5
Core Data comes with a built-in mechanism to handle changes to your model.
Take a look at the Core Data Model Versioning and Data Migration Programming Guide for details.

Alexander Vasenin
- 11,437
- 4
- 42
- 70

Thomas Zoechling
- 34,177
- 3
- 81
- 112
-
I've tried adding a new version to the Data Model, changing it and doing what it says here http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html but I still get the same error, even though this is supposed to make it work. – Joshua Jan 04 '10 at 11:13
-
Don't worry! Figured it out, this blog post here (http://sunflower.coleharbour.ca/cocoamondo/2009/06/core-data-migration/) details it nicely. – Joshua Jan 04 '10 at 12:30
-
-
I'm moving the blog entry here: http://weblog.preenandprune.com/2009/core-data-migration.html the old blog will be retired soon. – Matthieu Cormier Dec 07 '13 at 17:22
3
If 10.6 is your baseline OS then you can use lightweight migration, specifically NSInferMappingModelAutomaticallyOption.
The article I wrote is similar and useful if 10.6 is not your baseline OS.

Matthieu Cormier
- 2,185
- 1
- 21
- 32