Blog

CoreData Model Migration

by Thomas Spycher on August 11, 2010

If you are working on your project in XCode you will mostly use CoreData to handle the whole Data stuff. For this you designed a DataModel. Especially in the beginning of your project you need to change Attributes etc. very often in your DataModel.
After changing something in your DataModel and build the project you will be faced with e message, that tells you something about an incompatible persistensstore.


Your need to remove your serialized Data from your Harddisk and enter all your Testdata again.


CoreData can handle small changes in de DataModel by itself. You just need to activate this first.



  1. Locate the following method in your AppDelegate Class:
    - (NSPersistentStoreCoordinator *) persistentStoreCoordinator {
  2. Create an NSDictonary Object which contains the options.
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
    	[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
    	[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
    	nil];
  3. Search for the following statement:
        if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
                                                      configuration:nil
                                                                URL:url
                                                            options:nil
                                                              error:&error]){

    and change the options attribute to the following:

        if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
                                                      configuration:nil
                                                                URL:url
                                                            options:options
                                                              error:&error]){

Apple has a very good CoreData Migration whitepaper . This can be found here.

Wanna say something?