On migration between two non-consecutive versions (e.g. V11-V13) the migration fails with the error:
Can't find mapping model for migration
Creating a mapping model for every possible combination of versions. This works, but it's a real hassle.
For version 14 I'll need to make 14 different mapping models. Manually. Ugh.
Here's the options I pass in for migration:
[persistentStoreCoordinator addPersistentStoreWithType:[self storeType]
configuration:nil
URL:url
options:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:NO], NSReadOnlyPersistentStoreOption,
nil]
error:&error]){
My data model is pretty complex, but here it is: http://dl.dropbox.com/u/136780/Engine_V2_DataModel.xcdatamodeld.zip
I'm not using any version hash modifiers or renaming identifiers in my data model right now.
See this Stack Overflow question: Core Data Migration Across Multiple Version Upgrades
Basically, the gist is that you don't need to create the complete set of mapping models. You just need mapping models between each pair of successive models, and then you can progressively migrate any old model through the intermediate models to the newest model.
The performance may not be good depending on your store, because you're not doing the migration in one single step. It may be good enough, though, and may be worth it to not have to create the complete set of mapping models. You can also test out the performance of this method to determine whether you need to create maps between non-successive versions of your model.
Marcus Zarra (Core Data aficionado extraordinaire) has the code here: http://media.pragprog.com/titles/mzcd/code/ProgressiveMigration/AppDelegate.m
(I was just about to ask this question, but thanks to LazyTwitter I was pointed to this answer by Aaron Tuller: https://twitter.com/tullera/status/57708304683642880 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With