I have a project on that uses core data and I had migration implemented for whenever I needed to make a small change to my model. However, in the past week I’ve had to do a complete overhaul of my model and the way it reacts that I can not migrate any of the data.
With this I was wondering if there was a way to check what version of the model I have in the device and perhaps, through code, delete it and completely create a new one from scratch. This may not be the most preferred way, but if anyone has any better solutions than I am open to suggestions.
Two reasonable options:
Use NSManagedObjectModel’s usual versioning mechansim. Bump up the version of your new model. Core Data will automatically check to see whether a given store is compatible with one of the models in the app before it opens the store; if not, it’ll give you an error when you try to add it. So if you don’t provide the old model in your app, Core Data won’t use any old stores. You can respond to the error by deleting the store. You can also check a store before adding it using
-isConfiguration:compatibleWithStoreMetadata:. See Initiating the Migration Process for more.Use a different name for any stores you create using the new model. It’s not uncommon for an iOS app to use just one or two stores with specific names. You probably know the name you used for the store in previous versions of your app; switching to a different name gives you an easy way to know whether a store is compatible with the old or the new model.