I have Core Data application and I have been migrating (upgrading) the core data model. Each time I create a new version I create a mapping model for each version. Right now I have 16 versions and I have mapping models that go like this: 1to2.xcmappingmodel 2to3.xcmappingmodel 3to4.xcmappingmodel ...etc. up to 16
This works fine, but a problem arises when one user has a data file with version 10 and updates the application that has version 16. Some how I thought Core Data will automatically upgrade from 10 to 16, but an error shows up that says "Missing Mapping Model". To make sure the mapping models where correct, I upgrade it to each version one by one (10 to 11, 11 to 12, etc..) and it did work... Here is my code.
I specify the model version with this code:
NSBundle *modelWrapper = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"TaskApp_DataModel" ofType:@"momd"]];
NSString *modelPath = [modelWrapper pathForResource:@"TaskApp_DataModel 16" ofType:@"mom"];
NSLog(@"%@",modelPath);
managedObjectModel = [[NSManagedObjectModel alloc]initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];
And I define the Migrate Automatic option here:
NSURL *url = [NSURL fileURLWithPath: [applicationSupportDirectory stringByAppendingPathComponent: @"storedata-sql"]];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:url
options:dict
error:&error]){
Does anyone know how to upgrade this? Thank you.