Search code examples
iphoneiosxcodecore-datacore-data-migration

New Entity in CoreData with new Child


I previously asked a question about a problem of merging screens in an ElementListViewController and found a solution to my problem, but now I have a new one :

I has Promotion and Voucher which was child entities of Element.

Now I want to have Deal which is a child entity of Element but which is parent of Promotion and Voucher.

So my CoreData model is changed and I have a new Version. But I'm sure this will crash because of this (from Apple Doc) :

You cannot, however, merge entity hierarchies; if two existing entities do not share a common parent in the source, they cannot share a common parent in the destination.

So how can I build my new app without crashing ? Do I have to do a mapping model and that's all ? Or do I have to do a migration ? This Apple Doc is quite complete but I'm not sure to really understand.

Thank you !


Solution

  • You need to do manual migration. I don't know what is the right way to do that, but I've done similiar things this way - I create new entities and after automatic migration I do my own database update which moves records from old entity to new one. Unfortunately there are still old entities in datamodel which stay unused anymore and thats the bad thing.