I've found nothing about migration rules
in case of changing the deletion rule
of a managedObjects relationship
My initial coredata model contained an entity with a relationship. The delete rule of this relationship was cascade
. I had to change this behavior to Nullify
.
Therefore I've created a new version of my coredata model
but without any lightweight migration and it still works. So I wounder if I should have done adding a new version of my model or if the changing the deletion rules (e.g. from cascade
to nullify
) doesn't effect/need any migration.
Any suggestions?
A delete rule defines what happens when the record that owns the relationship is deleted. A delete rule defines what happens when the record that owns the relationship is deleted. Select the notes relationship of the Category entity and open the Data Model Inspector on the right.
Put another way, there is a to-one relationship between a managed object and the data record it represents, but a to-many relationship between the record and corresponding managed objects. Core Data does not let you create relationships that cross stores.
Setting the Delete Rule to Protect prevents deleting records of the main Entity while there are associated records in the related Entity. This behavior is ensured by a database constraint created on the reference attribute.
Deletion rules specify the behavior of Core Data at runtime: If one object is deleted, other relationships may be set to NULL, or related objects may be deleted as well.
Therefore I assumed that the deletion rules are stored only in the Core Data model, but not in the persistent store file.
To verify this, I have created 2 store files from 2 Core Data models with identical entities, but different deletion rules. The NSStoreModelVersionHashes
in the persistent stores metadata
dictionary were identical.
In fact, both SQLite files were identical with the only exception of the "Z_UUID" in the "Z_METADATA" table, which is the NSStoreUUID
of the persistent store file.
Also, addPersistentStoreWithType:...
would fail if the version hashes of the loaded store are different from the hashes in the model.
Changing the deletion rules should therefore not be a problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With