Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do when get "The model used to open the store is incompatible with the one used to create the store"?

Tags:

core-data

I had a core data EntityDescription and I created data in it. Then, I changed the EntityDescription, added new one, deleted the old one using the editor for xcdatamodeld file.

Now any of my code for core data causes this error "The model used to open the store is incompatible with the one used to create the store}". The detail is below. What should I do? I prefer to remove everything in the data model and restart new one.

Thanks for any suggestion!

 reason=The model used to open the store is incompatible with the one used to create the store}, {
    metadata =     {
        NSPersistenceFrameworkVersion = 320;
        NSStoreModelVersionHashes =         {
            Promotion = <472663da d6da8cb6 ed22de03 eca7d7f4 9f692d88 a0f273b7 8db38989 0d34ba35>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
        );
        NSStoreType = SQLite;
        NSStoreUUID = "9D6F4C7E-53E2-476A-9829-5024691CED03";
        "_NSAutoVacuumLevel" = 2;
    };
like image 817
user1039552 Avatar asked Nov 10 '11 10:11

user1039552


2 Answers

Or if you're in dev mode, you can also just delete the app and run it again.

like image 92
Kangt_qc Avatar answered Nov 09 '22 12:11

Kangt_qc


Deleting the app is sometimes not the case! Suggest, your app has already been published! You can't just add new entity to the data base and go ahead - you need to perform migration!

For those who doesn't want to dig into documentation and is searching for a quick fix:

Open your .xcdatamodeld file

click on Editor

select Add model version...

Add a new version of your model (the new group of datamodels added)

select the main file, open file inspector (right-hand panel) and under Versioned core data model select your new version of data model for current data model

THAT'S NOT ALL ) You should perform so called "light migration".

Go to your AppDelegate and find where the persistentStoreCoordinator is being created

Find this line if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])

Replace nil options with @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} (actually provided in the commented code in that method)

Here you go, have fun! P.S. This only applies for lightweight migration. For your migration to qualify as a lightweight migration, your changes must be confined to this narrow band:

Add or remove a property (attribute or relationship). Make a nonoptional property optional. Make an optional attribute nonoptional, as long as you provide a default value. Add or remove an entity. Rename a property. Rename an entity.

Answer borrowed from Stas

like image 12
Vijay S Avatar answered Nov 09 '22 13:11

Vijay S