I have an existing core data set and I want to add an entity to it. I’m a little confused over whether I can use lightweight migration after adding a new entity to transition existing users to the new model.
The current modal is (just showing entities):
Story 1toMany-> Sentences
I need:
Story 1toMany-> Sentences 1toMany-> Media
Can I use the lightweight migration tool to do this?
I’ve read in the documentation:
For Core Data to be able to generate an inferred mapping model,
changes must fit an obvious migration pattern, for example:Simple addition of a new attribute Removal of an attribute A
non-optional attribute becoming optional An optional attribute
becoming non-optional, and defining a default value Renaming an entity
or property
But this question seems to suggest lightweight migration will still work with the addition of an entity. Since the new media entity is optional I can’t see how it would practically be a problem.
Check the core data video “Mastering core data” from wwdc 2010. They talk about migration for your specific case. Long story short: yes, you can use lightweight migration. Just pass the options dictionary when initializing the NSPersistentStoreCoordinator instance: