I created an application a while back which uses Core Data in order to store information. Today I made a couple of changes to the Data Model and recreated the code files for which I changed data models. When I tried running the application on my iPad again, it complained that there is a clash between the datastore currently on the iPad, and the one I am trying to access (I added one field to one of the objects). I resolved this issue by completely removing the application from my iPad and replacing it with the new version.
I’m just wondering now, what will the implications for the users currently using the application be when I release the update? Will they also loose all their data? Will they be confronted with that ugly error message or crash? Or does Core Data magically upgrade the datastore for me?
Regards,
EZFrag
See the Apple Core Data Migration Guide at: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html.
“You can only open a Core Data store using the managed object model used to create it. Changing a model will therefore make it incompatible with (and so unable to open) the stores it previously created. If you change your model, you therefore need to change the data in existing stores to new version—changing the store format is known as migration.
To migrate a store, you need both the version of the model used to create it, and the current version of the model you want to migrate to. You can create a versioned model that contains more than one version of a managed object model. Within the versioned model you mark one version as being the current version. Core Data can then use this model to open persistent stores created using any of the model versions, and migrate the stores to the current version. To help Core Data perform the migration, though, you may have to provide information about how to map from one version of the model to another. This information may be in the form of hints within the versioned model itself, or in a separate mapping model file that you create.”