Reputation: 912
I have a model Version
. The entity passPhrase
of Version
needs to be migrated to New entity passPhrase
in Home
model.
But the Home
model is introduced in new version of database. It was not present in old xcdatamodel
. How can I migrate data from
Version.passPhrase to Home.passPhrase
Upvotes: 0
Views: 259
Reputation: 12003
And the golden rule of CoreData migration is - avoid custom migration at any cost. :)
So the way to do this to use lightweight migration to add your new entity, and then just use a one off migration script to move your data over.
You can remove the passPhrase
property from your Version
class definition but you need to leave it in the model for now so you can still access the old data. This can be cleaned up at some time in the future when you are confident all of your users have upgraded to the newer version, or just leave it there forever.
To access the existing value during your copy just use [version valueForKey:@"passPhrase"]
and then once copied clear it out the same way [version setValue:nil forKey:@"passPhrase"]
Upvotes: 1
Reputation: 1573
In core data, Changing Entity / Model mapping does not comes under light weight migration. You have to handle it manually by subclassing NSMigrationManager and implementing custom NSEntityMigrationPolicy.
Apple provides little documentation on the subject.Please check the Custom Core data migration with detailed example. Hope this will help.
Upvotes: 0