I have an existing core data project now I want to add some more tables into it so my question is do we need to add change current version of CoreData and add new version to it ? Also my app is already live. Now I want to publish another version of application by adding some more tables to it.
- December 6, 2022
- 234 views
- 0 votes
- 2 Answers
-
-
2
Answers
It is better to make an explicit migration, especially if you have your app live and there is user data in the field.
Core Data has a method for it, the
Lightweight Migration. Core Data can typically perform an automatic data migration, referred to as lightweight migration. Lightweight migration infers the migration from the differences between the source and the destination managed object models.
If you want to adapt also parts of your old model, when they are affected by your changes you may use the Heavyweight Migration
There you may migrate the old user data and you can change your old model if it is affected by your changes and your changes are logically complex.
Nevertheless if there are no changes which affect your old model you may also only add a table, but I personally migrate…..
https://developer.apple.com/documentation/coredata/using_lightweight_migration
Core Data Migration
In order to follow core data migration we should keep on versioning our .xcdatamodeld file. Also to address new changes we should not make any changes in existing data model. Instead we should create a new version of .xcdatamodeld and perform changes there. We should follow core data migration if there are changes in:
Entity –
Add a entity,
Remove a entity,
Renaming a entity.
Attribute-
Add an attribute,
Remove an attribute,
Renaming an attribute,
Relationship –
Add a relationship ,
Remove an relationship ,
Renaming an relationship .