Reputation: 103
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;
};
Upvotes: 10
Views: 16503
Reputation: 185
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
Upvotes: 12
Reputation: 420
Or if you're in dev mode, you can also just delete the app and run it again.
Upvotes: 20
Reputation: 1385
Reset your simulator and run again. If you were to run with a different device in the simulator, it would work. If you are running with an iphone 6s simulator and you try to run 6s plus, it would still work without resetting.
If running on a phone, make sure to delete the app and rerun it
Upvotes: 1
Reputation: 4013
Delete your app on simulator and restart:
On simulator, go to Hardware -> Home:
Click and hold mouse button on your application icon:
Click on "X" in app icon to delete:
Go back to Xcode and restart your application(Command+R):
or:
PS.: If the error appears again, review your code because the problem should be in the syntax or discrepancy between what you want to list with the data model that you have.
Upvotes: 2
Reputation: 1097
I have faced the same issue using Xcode 7 beta 1 and the following action has resolved the issue. Menu==>> click on Window>Projects>select project on the left hand side and click on delete button which is located on the right side. If still doesn't work, => reset the simulator and run the app
Upvotes: 0
Reputation: 1628
If this is a non-production app, just delete your local database (appname.sqlite) and restart the app.
Upvotes: 5
Reputation: 183
If this is a non-production app, just delete your local database (appname.sqlite) and restart the app.
I find I'm always doing this, and so provide the following additional detail:
Under XCode 4 (4.3.2) you should find your datastore here:
/Users/~/Library/Application Support/iPhone Simulator/simulatorVersion/Applications/yourAppIdentifier/Documents
Or you can use Spotlight, if you first enable searching for System Files; I've found it fastest to save such a search to the menu bar.
Upvotes: 6