Reputation: 201
I made a new version of my core data model which includes one new entity "Test" with one attribute "type". The lightweight migration worked with no errors but I noticed that the new entity was not created in the database. When fetching this new entity "Test" , the result was nil. I had the attribute "type" set as non-optional with a default value of 1 because I expected that the migration will create the new entity with this default value . But it didn't. So my question is : is this expected behavior? In the case of core data migration, the new entities are not created but set as nil? Or if I am missing some steps , what happens if the new model has relationships between the new entity "Test" and the existing entities? Thanks.
Upvotes: 0
Views: 289
Reputation: 6508
You need to create an object of this entity, using for example -[NSEntityDescription insertNewObjectForEntityName:...]. Simply having the entity in the model will not create any objects.
You can do this at the end of migration, or lazily at startup (if you do a fetch for an object of this entity and can't find it).
Upvotes: 0