I have read a few articles indicating that there should be light weight migration whenever there is a change in entity, attribute or relationship. But a few days ago when I was talking to my senior he asked me if lightweight migration is really required when a new attribute is added. This got me confused. I know that we should always create a new version before making any changes in the Core Data model. So does it mean that versioning is the same as migrations. Do we need migration if we rename an existing attribute. I would really appreciate if someone could help me.
Do we need migration when we add a new attribute to an existing entity?
A migration is required but you do not created it on your own. Adding a property is perfectly covered by automatic lightweight migration. When you add a property to the core data schema and open an existing store with lightweight migration enabled the existing store will seamlessly be migrated.
As a rule of thumb, when adding new entities or properties to existing entities you're fine with automatic lightweigth migration. For type changes and renaming of existing properties you most probably need to create a heavyweight migration or data will be lost when opening existing stores with the new schema.
Is migration and versioning the same thing
No. Versioning refers to the core data schema while migration is applied to an existing store. You should add a new schema version when you're about to change existing entities or relationships. Furthermore it's important to add a new schema before changing anything in the schema when you had created a heavyweight migration with this schema as target. Otherwise the migration will break because it has no matching target anymore.
© 2022 - 2024 — McMap. All rights reserved.