Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does adding a new independent entity in Core Data require model versioning?

I want to add a new Core Data Entity in my project. Do I need to add a new core-data Model Version for this or it will work within existing version? The entity is independent and it will have no relation with other previously defined entities.

like image 908
atulkhatri Avatar asked Oct 16 '25 03:10

atulkhatri


1 Answers

Indeed, it requires adding a new model version. However, adding a new entity can be handled by a lightweight migration, so at least you don't have to create a mapping model/write custom migration code.

UPDATE:

From the article about lightweight migration:

In addition, Core Data supports: ... Changing the entity hierarchy

  • You can add, remove, rename entities
  • You can create a new parent or child entity and move properties up and down the entity hierarchy
  • You can move entities out of a hierarchy
  • You cannot, however, merge entity hierarchies; if two existing entities do not share a common parent in the source, they cannot share a common parent in the destination

And if you don't use versioning, you'll get an error like this:

Error Domain=NSCocoaErrorDomain Code=134100 "(null)" UserInfo={metadata={ NSPersistenceFrameworkVersion = 641; NSStoreModelVersionHashes = { TestEntity1 = ; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "F16AD345-02FE-4E94-B11E-3BC337B16568"; "_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is incompatible with the one used to create the store} with userInfo dictionary { metadata = { NSPersistenceFrameworkVersion = 641; NSStoreModelVersionHashes = { TestEntity1 = ; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "F16AD345-02FE-4E94-B11E-3BC337B16568"; "_NSAutoVacuumLevel" = 2; }; reason = "The model used to open the store is incompatible with the one used to create the store"; }

This looks like a good reason to use versioning to me)

like image 143
FreeNickname Avatar answered Oct 18 '25 17:10

FreeNickname



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!