Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data Force Custom Mapping Model/Policy instead of Lightweight Migration

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?

like image 477
Cory Imdieke Avatar asked Nov 09 '10 18:11

Cory Imdieke


People also ask

What is migration in CoreData?

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.

Can't find or automatically infer mapping model for migration?

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.

What is Persistentcontainer in core data?

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 ).


1 Answers

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

like image 97
logancautrell Avatar answered Sep 28 '22 20:09

logancautrell