NSPersistentStoreIncompatibleVersionHashError
Man. This error has been driving me nuts for a few days now. I’ve got my iPhone app up and running, everything works great until I try and run a
[managedObjectContext save:&error]
Without saving everything works just fine (though it doesn’t restore data when I restart, obviously). Whenever I try and save, though, I get the following error.
This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.
After finally looking in what turned out to be a pretty obvious place, the declaration of the Persistent Store Coordinator in the App Delegate, the default code generated by XCode doesn’t do any error handling. Here’s what I replace it with:
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
if ([error code] == NSPersistentStoreIncompatibleVersionHashError)
NSLog(@"Persistent Store Incompatible Version error. Please check %@", storeUrl);
else {
NSLog([error description]);
}
}
Check it. Turns out that changing your data model after you’ve already run the code once will render your database inoperable. Of course, there are techniques to upgrade your database to the new model, but at this point I don’t care. Delete the old database and next time you run the code, everything will move through smoothly, and your new database will be saved.