When I started developing the application, I had a Core data model with 5 entities (with the name Visitors, UnreadMessages, ContactStatuses, UserVCardand User). The app appeared live on the app store. There is no problem. Now I had to add some changes to the requirements, so the main data model changed slightly, adding 2 more objects to it (with the name AudioSupportedWindowsand AudioMessages)
Thus, according to many articles, SO posts, and documentation for Apple, the migration method was LightWeight migration , so I added the following code for this
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
NSError *error;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSLog(@"Problem with PersistentStoreCoordinator: %@",error);
}
in my method persistentStoreCoordinator. But he always gives an error . Can't find model for source store
, - ()
, , , , 5 . The model used to open the store is incompatible with the one used to create the store
em ... .
1
- (NSManagedObjectModel *)managedObjectModel
{
if (managedObjectModel != nil)
{
return managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"UserData" withExtension:@"momd"];
managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel;
}