Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling Core Data Model Changes

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?

like image 954
Joshua Avatar asked Feb 27 '23 20:02

Joshua


2 Answers

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.

like image 78
Thomas Zoechling Avatar answered Mar 12 '23 18:03

Thomas Zoechling


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.

like image 45
Matthieu Cormier Avatar answered Mar 12 '23 18:03

Matthieu Cormier