Tuesday, November 24, 2015

The model used to open the store is incompatible with the one used to create the store

If you are working on an iOS app and have used Core Data in your app you might suddenly come across an error with any of these messages: "The model used to open the store is incompatible with the one used to create the store," "Failed to initialize the application's saved data," or "There was an error creating or loading the application's saved data."

Don't fret, this simply means some of the data model for your Core Data has changed, it could be something as simple as adding a new attribute to an entity in Core Data, or modifying the data type of an attribute. Luckily the solution is quite simple in most cases - you can simply delete the app from your device or simulator and install/run the app again and it should work fine.

Note how I said the solution is simple for most cases; that's because it is not always practical to delete the app before installing the new version - either because you are testing upgrade functionality that you cannot test if you uninstall the app, or because you want to launch the app in the App Store and can't really expect your users to uninstall your app before installing an update. That's a sure way to have your app permanently uninstalled from the user's device! Unfortunately in this case modifying items in Core Data is not as easy; you'll have to migrate your data which entails writing some code to take care of it. I'll cover this in a future post but the solution above should work for over 90% of your needs while in development.

Paras Wadehra
Microsoft MVP
My WP Apps

No comments: