NSPersistentCloudKitContainer: Migration failed based on alphabetical order

I added a new Core Data model version, introducing a new entity.

Based on the naming of the Entity I get different behaviour:

A: If the entity is alphabetically ordered as last entity: Everything works fine.

B: There entity is ordered before already existing entities:
  1. All records of these existing entities get a new CloudKit id. Resulting in duplicated data and broken relations.

  2. In some cases the seem-to-be new insert of these records causes the migration to fail. (Constraint unique violation, reason=constraint violation during attempted migration)


My only workaround so far is to just give the entity a different name, to appear last in the list.
__

Does anyone else experience this issues? I am not sure if my code could be able to trigger this kind of behaviour.

I will try to reproduce it in an empty project, to file a bug report.

Accepted Reply

Got resolved in iOS 14 beta 3 🥳

Replies

Please file a bug.
Filed Feedback Report FB7772705
Got resolved in iOS 14 beta 3 🥳
Wow thanks a lot for posting this here, I just spent a lot of time trying to debug this exact problem. As you wrote, I had added a new entity with a name between existing entities. I got an constraint violation during attempted migration error. And indeed saw in the log there were new ID's assigned to each of the entities. When I put a Z in front of the name it works!

Problem is, this could be solved in iOS 14, but what about iOS 13? Do I have to keep adding Z's to entity names while supporting iOS 13?