is anyone facing the error, "The current model reference and the next model reference cannot be equal", when using SwiftData with migration and iCloud/CloudKit integration?
The current model reference and the next model reference cannot be equal.
Did you ever figure out the problem? I just ran into it myself and don't see anything obviously wrong. If I figure it out, I'll post again here with my findings.
I just figured it out in my case.
Each of my two 2 VersionedSchemas, V1 and V2, was referring to its static models as [A.self, B.self], which is fine. But I had forgotten that I had also typealiased A and B to the current schema ("typealias A = V1.A"), which was overriding the static references.
I fixed it by referring to the static models within the VersionedSchemas as [Self.A.self, Self.B.self], avoiding confusion with the typealiases.
I came across this while googling and thought I'd also put my solution here for any others it helps:
I was bumping the schema just to use the migrations for ensuring data integrity, and I hadn't actually changed the model. Once I made a change to the model (renamed an attribute I had been meaning to get around to) everything worked fine.
Thanks Guys. The type alias stuff was getting me. I manually put the static declaration with the class in front to avoid my confusion.
Here's my latest VersionedSchema for clarity.
enum ModelSchemaV5: VersionedSchema {
static var versionIdentifier = Schema.Version(5, 0, 0)
static var models: [any PersistentModel.Type] {
[
// V1
ModelSchemaV1.SDAccountingClass.self,
ModelSchemaV1.SDCacheRecord.self,
ModelSchemaV1.SDCustomer.self,
ModelSchemaV1.SDItem.self,
ModelSchemaV1.SDLocation.self,
ModelSchemaV1.SDTag.self,
ModelSchemaV1.SDUOM.self,
// V2
ModelSchemaV2.SDPurchaseOrder.self,
ModelSchemaV2.SDPurchaseOrderItem.self,
ModelSchemaV2.SDVendor.self,
ModelSchemaV2.SDCarrier.self,
ModelSchemaV2.SDInventoryLocationSummary.self,
ModelSchemaV2.SDPurchaseOrderSettings.self,
// V3
ModelSchemaV3.SDShip.self,
ModelSchemaV3.SDSalesOrder.self,
// V4
ModelSchemaV4.SDReceipt.self,
ModelSchemaV4.SDDocument.self,
// V5
ModelSchemaV5.SDReceiptItem.self
]
}
}