change NSManagedObject parent entity in another version

332 Views Asked by At

Is there any good way to change parent entity of an NSManagedObject in another version?
Lets say on model version 1.1 I got:

  • anObject - with no parent entity

in version 1.2 i want to make it inherit from

  • object - a parent class that already exist in version 1.1 and containing the property "objectID"

When i change it's parent entity the application crash with:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot create managed object contexts: The persistent store coordinator does not have any persistent stores. This likely means that you forgot to add a persistent store or your attempt to do so failed with an error.'

In this answer it's suggested to create new entities with different names in a new version, and delete the old ones.
My question is if there is a 'cleaner' solution for this kind of problem?
How do i add a mapping model to the project/ current model?

1

There are 1 best solutions below

1
On BEST ANSWER

O.k the solution is quite simple,
You make the required changes in the model (change the "anObject" parent entity)
Then all you need to do is add a new mapping model, by selecting "New File" -> "Core Data" -> "Mapping Model"

Add a new mapping model

Make sure you make the changes in the model before adding the new mapping model!
Then select the source data model (in my case version 1.1) and the target data model (1.2), and create the new mapping model.
For me it was that simple, didn't even needed to make any changes in the new mapping model. II'd like to here if anyone have any comments about pros and cons for using mapping models.