Hello,
I'm using CoreData + CloudKit and I am facing the following error 134100 "The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store."
All my schema updates are composed of adding optional attributes to existing entities, adding non-optional attributes (with default value) to existing entities or adding new entities Basically, only things that lightweight migrations can handle.
Every time I update the schema, I add a new model version of xcdatamodel - who only has a single configuration (the "Default" one). And I also deploy the updated CloudKit schema from the dashboard.
It worked up to v3 of my xcdatamodel, but started to crash for a few users at v4 when I added 16 new attributes (in total) to 4 existing entities.
Then again at v5 when I added 2 new optional attributes to 1 existing entity.
I'm using a singleton and here is the code:
private func generateCloudKitContainer() -> NSPersistentCloudKitContainer {
let container = NSPersistentCloudKitContainer(name: "MyAppModel")
let fileLocation = URL(...)
let description = NSPersistentStoreDescription(url: fileLocation)
description.shouldMigrateStoreAutomatically = true
description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
let options = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.com.company.MyApp")
options.databaseScope = .private
description.cloudKitContainerOptions = options
container.persistentStoreDescriptions = [description]
container.viewContext.automaticallyMergesChangesFromParent = true
container.loadPersistentStores { description, error in
container.viewContext.mergePolicy = NSMergePolicy(merge: .mergeByPropertyObjectTrumpMergePolicyType)
if let error {
// Error happens here!
}
}
return container
}
I can't reproduce it yet. I don't really understand what could lead to this error.