when i started developing the app, I had a Core data model with 5 Entities (named Visitors, UnreadMessages, ContactStatuses, UserVCard
and User
). The app went live on app store.. no issue in that.. Now i had to add some requirement changes so the core data model changed minorly by having 2 more entities added to it (named AudioSupportedWindows
and AudioMessages
)
So according to a lot of articles, SO posts, and apple documentation, The way to migrate this was LightWeight migration so for that I added the following code
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]) {
// Handle error
NSLog(@"Problem with PersistentStoreCoordinator: %@",error);
}
in my persistentStoreCoordinator
method. But it always gives a Can't find model for source store
error.
After that I started of with manual migration using a migration mapping according to this link Core Data - Default Migration ( Manual )
But when i run this I get both source and destination models but they are identical that is they both consisting on 5 entities. and i get this error The model used to open the store is incompatible with the one used to create the store
terribly em in deep trouble ryt now solving this… any help would be greatly appreciated.
Edit 1
- (NSManagedObjectModel *)managedObjectModel
{
if (managedObjectModel != nil)
{
return managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"UserData" withExtension:@"momd"];
managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel;
}