I'm trying to upgrade my current application to use an abstract parent entity, with specialized sub entities. I've created a custom NSEntityMigrationPolicy, and in the mapping model I've set the Custom Policy to the name of my class.
I'm initializing my persistent store like this, which should be fairly standard :
NSError *error=nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
nil];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSLog(@"Error adding persistent store : %@",[error description]);
NSAssert(error==nil,[error localizedDescription]);
}
When i run the app i get the following error :
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The operation couldn’t be completed. (Cocoa error 134140.)'
[error userInfo] contains "reason=Can't find mapping model for migration"
I've verified that version 1 of the data model will open, and if i set NSInferMappingModelAutomaticallyOption i get a migration, although my entities are not migrated correctly (as expected).
I've verified that the mapping model (cdm) is in the application bundle, but somehow it refuses to find it. I've also set breakpoints and NSLog() statements in the custom migration policy, and none of it runs, with or without NSInferMappingModelAutomaticallyOption
Any hints as to why it seems unable to find the mapping model ?
First, abstract entities have a rather large penalty attached to them. All children of the abstract will be stored in the same table. This will create a very wide table with a lot of voids. I would suggest reviewing your data model and making sure that is what you really want.
Second, if you cannot find the mapping model that means it is not lining up with either the source or the destination. If you changed the destination after creating the mapping model, it won't find the map. Creating a mapping model needs to be the last step after the new model is finished. I would even recommend locking the model.