We've recently decided to add a few optional Double-typed attributes (named last7
, last30
, and last60
) to our Product
CoreData entity, but this is causing an NSInternalInconsistencyException
:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Property named 'sortKey' in entity 'Comment' conflicts with property inherited from parent entity 'ChatItem''
Comment
is a subclass of ChatItem
, and the sortKey
is a String attribute declared in ChatItem
, inherited by Comment
. Comment
has a fetch index on the sortKey
property; removing this does not solve the problem.
As you can see in this connector view screenshot, Product
s are tangentially related to these two classes via the Event
entity; each Product
has a number of Event
s and each Event
has a number of ChatItem
s. In practice, most of these ChatItem
s are of the subclass Comment
.
Marking the new properties "transient" resolves the crashing issue, but does not store the data in CoreData, which is a requirement for these values.
We've noticed that this issue does not occur on clean installs, so we assume it's related to migrations in some way. Based on the accepted answer on this very similar StackOverflow question (Preventing a CoreData crash for upgrading users), we verified we have enabled lightweight migrations:
let options = [
NSMigratePersistentStoresAutomaticallyOption: true,
NSInferMappingModelAutomaticallyOption: true,
NSSQLiteAnalyzeOption: true,
NSSQLiteManualVacuumOption: true
]
store.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: self.storeURL, options: options)
We're confused because the property which is ostensibly causing the issue is not a part of an entity which we are changing; what are we missing?