I will try to answer you as best as possible, I have experienced the migration of basic data several times, so I know how painful it is. For one, you cannot hope that your migration will work with these parameters, because what you are trying to do is not really easy portability, and yet you say that it makes migration easier.
In principle, suppose that for some reason you need to have an easy migration between the 2 versions, in your case 11 and 12. What you need to do is do this:
1-> 12 light weight 12-> 13 user migrations 13 β (future version) light migration
There may be a better solution, but I have not found it yet.
Here is some code that will help you (the most difficult parts, I canβt remember everything idle), before this code I copy the database to a backup, so basically the backup database is your old and your storage is new (which is empty)
NSString *path = [[NSBundle mainBundle] pathForResource:<YOUR MODEL NAME> ofType:@"cdm"]; NSURL *backUpURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"<YOUR MODEL NAME>MigrationBackUp.sqlite"];
Then just do the migration with your source and destination.
This is also the hard part:
BOOL success = [migrator migrateStoreFromURL:backUpURL type:NSSQLiteStoreType options:nil withMappingModel:mappingModel toDestinationURL:storeURL destinationType:NSSQLiteStoreType destinationOptions:nil error:&err2];
And last but not least (I said I will give it to you earlier):
- (NSManagedObjectModel *)managedObjectModelForVersion:(NSString*)version { NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"Model" ofType:@"momd"]; if (BETWEEN_INEX(version, @"1.0", @"1.4")) { modelPath = [modelPath stringByAppendingPathComponent:@"Model"]; modelPath = [modelPath stringByAppendingPathExtension:@"mom"]; } else if (BETWEEN_INEX(version, @"1.4", @"1.5")) { modelPath = [modelPath stringByAppendingPathComponent:@"Model 2"]; modelPath = [modelPath stringByAppendingPathExtension:@"mom"]; } else if (BETWEEN_INEX(version, @"1.5", @"1.6")) { modelPath = [modelPath stringByAppendingPathComponent:@"Model 3"]; modelPath = [modelPath stringByAppendingPathExtension:@"mom"]; } else if (BETWEEN_INEX(version, @"1.6", @"1.7")) { modelPath = [modelPath stringByAppendingPathComponent:@"Model 4"]; modelPath = [modelPath stringByAppendingPathExtension:@"mom"]; } NSURL *modelURL = [NSURL fileURLWithPath:modelPath]; NSManagedObjectModel * oldManagedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; NSSet *vIdentifiers = [oldManagedObjectModel versionIdentifiers]; for (NSString * identifier in vIdentifiers) { NSLog(@"Old Model : %@",identifier); } return [oldManagedObjectModel autorelease];
}
I know these are just snippets of code, but I really hope this helps you solve your problem, if you need anything else, just ask.