I am trying to migrate my current core data structure to a new data structure however I am continually getting the same error no matter what I do:
Terminating app due to uncaught exception 'Open Failed', reason: 'Reason: The operation couldn’t be completed. (Cocoa error 134100.)'
According to the documentation this means: NSPersistentStoreIncompatibleVersionHashError
I cannot just erase the app from the simulator as it has already gone out to the app store.
The persistent store coordinator in the app delegate is as follows:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"DATABASELOC.sqlite"];
NSLog(@"URL: %@", storeURL);
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
}
And my managedobjectmodel within the app delegate is as follows:
- (NSManagedObjectModel *)managedObjectModel
{
if (managedObjectModel != nil) {
return managedObjectModel;
}
NSString *path = [[NSBundle mainBundle] pathForResource:@"DATABASELOC" ofType:@"momd"];
NSURL *momURL = [NSURL fileURLWithPath:path];
managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];
return managedObjectModel;
}
I have generated a second model version, and updated the current version, and if I choose either as the current, if it is the same as the original model it loads fine. However as soon as I make a minor change the model that is current the same error comes up.
I guess it appears that it is not recognizing that there is a new model, but no matter what I do I cannot get past this error.
Has anyone else had this problem? Can anyone offer some advice?
Let me know if you need any more information.
Thanks in advance for your help!