I've got about 4 different versions of my data model now, and every one except the last one has been just a minor change using automatic lightweight migration. For this latest model, I need to do a bit of additional work during the migration, so I created a custom mapping model and a migration policy subclass with some actions in the createDestinations and createRelationships. Problem is, my mapping model/custom policy isn't being called, and it seems that Core Data is trying to perform lightweight migration instead. Is there something I need to do to keep lightweight migration around, but use my mapping model when there's one available?
Core Data can typically perform an automatic data migration, referred to as lightweight migration. Lightweight migration infers the migration from the differences between the source and the destination managed object models.
If you set DM2 as the active version then run your app, a migration will run on your persistent store. If you then make another change to DM2, run your app... Boom! The issue is that your store has already been migrated to "DM2" but the data in the store doesn't fit into the model anymore.
NSPersistentContainer simplifies the creation and management of the Core Data stack by handling the creation of the managed object model ( NSManagedObjectModel ), persistent store coordinator ( NSPersistentStoreCoordinator ), and the managed object context ( NSManagedObjectContext ).
You have to change the way your PSC is being initialized. Try setting both NSInferMappingModelAutomaticallyOption and NSMigratePersistentStoresAutomaticallyOption to YES. See http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/CoreData/Articles/cdUsingPersistentStores.html
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