What happens when a newer version of my app changes the database format?

What do I do if a newer version of my app uses a database that has a change from the database in the older version of the app. Would there be a crash when the app is installed or would there be a crash when a save or a fetch is done?

Replies

CoreData has a feature called "migration" for dealing with changes to the database schema. (Note, you have to add code to turn migration on, depending on what your CoreData code looks like.)


In earlier versions of CoreData, you'd have to include every previously released schema in your app (there's the bundle version of the model files to do that conveniently) so that the migration could be calculated out. In more recent versions (at least according to the WWDC videos) the schema information is getting encoded in the datastore so you probably don't need all of the previous schema.


If you make drastic enough changes to the model, you exceed what the lightweight migration can do and need to add code to convert the old objects to the new schema.


Long story short: If there's a crash, it should be when you add the persistent store, not when you do a fetch or save.