I've found documentation very limited and my problem solution nowhere.
I need to add new entity (with relationship to existing one). Also add and rename some of attributes of existing entity.
Lightweighted example:
Old model has one entity Item
with one attribute name
.
In new model I want to Item
to have one new attribute dateAdded
and rename name
to title
. At this point, if dateAdded
would be optional or given default value, I could use lightweight migration feature. Correct me if I am wrong.
But I also want to add new List
entity with title
attribute. And add to-many relationship. List can be empty or have many items. Item have to refer to exactly one list.
So I am confused in what everything I have to do and what order.
Turn on migration with lightweighted migration feature disabled (NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:NO], NSInferMappingModelAutomaticallyOption, nil];
).
Create a new version of model. There I do changes I want to.
Create a new mapping model. Source is old model, target is new model. In ItemToItem
I set title
to $source.name
.
Besides Xcode is still crashing on working with mapping model I do not know what to do next. I think I have to create one instance of List
in context and make all items referring to it because of relationship policy. And I thing I should use custom NSEntityMigrationPolicy
to do this. Any help to accomplish this challenge?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…