CloudKit - Cannot create or modify field 'CD_nameFirstChar' in record 'CD_Charts' in production schema

Some of my users are reporting an inability to sync via CloudKit between devices. I have not seen it on any of my devices, but one user got me some console logs that are showing the following error:

<CKError 0x600000a0f840: "Partial Failure" (2/1011); "Failed to modify some records"; uuid = EDC7B3E3-02F8-43B7-83B6-22D17EF0442A; container ID = "iCloud.cribaudo.iphemeris"; partial errors: { C611E11F-3DC0-484C-8FC1-23473062D9D0:(com.apple.coredata.cloudkit.zone:defaultOwner) = <CKError 0x600000a04660: "Invalid Arguments" (12/2006); server message = "Cannot create or modify field 'CD_nameFirstChar' in record 'CD_Charts' in production schema"; op = D83EF1F7DD772042; uuid = EDC7B3E3-02F8-43B7-83B6-22D17EF0442A>

I do not understand this:

  • The field CD_nameFirstChar was added to the data model in the version 15.
  • Automatic Migration is enabled.
  • The CloudKit Console says the Private Database Container being used by my App is deployed to production.
  • The entity CD_Charts (I only have one) that is deployed to production shows that field as present (CD_nameFirstChar).
  1. Why would this user be getting this error? As far as I can see they are running a version where migration to Model 15 should have been triggered at some point in the past.

  2. If somehow something went wrong with their migration, how would I fix it?

Any thoughts / ideas are appreciated.

One thing I should add is that the migration from Model 14 to 15 was not lightweight. I did use:

@interface ModelMigration14to15 : NSEntityMigrationPolicy
-(NSString *)nameFirstChar:(NSString *)name;
@end

And I used a MapModel14to15 which used the above function to set the value of nameFirstChar. The Value Expression for that attribute is:

FUNCTION($entityPolicy,` "nameFirstChar:" , $source.name) 

from the above mentioned NSEntityMigrationPolicy class.

This worked ok on all my devices and apparently on some user devices. This issues seems to effect only a small subset of my users but not all? So I am at a loss to understand why this would happen or how to fix it.

Accepted Reply

Typically this means you never updated the production schema with CD_nameFirstChar.

https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit

  • You might not be wrong see my reply below. But I am at a loss as to how it happened. Also I do not see those errors on my Console or any of the OS_Logs I am getting from some TestFlight users now. In fact I am not seeing ANY CKERRORS for the two testers I have who are reporting the issue.... and yet not updating. ... By the way dude, thanks for the reply. Any other thoughts based on the below?!

  • So on the cloudkit console deploy schema changes was still available on the Development container. I don't understand that actually because I thought I read someplace that if the initialization code listed below is run then the Dev schema is deployed and that once an App runs on production using that schema that it automatically gets deployed to production? Someplace I developed a misconception. I used the deploy option and now I see the field on the production container. So THANKS!

Add a Comment

Replies

Typically this means you never updated the production schema with CD_nameFirstChar.

https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit

  • You might not be wrong see my reply below. But I am at a loss as to how it happened. Also I do not see those errors on my Console or any of the OS_Logs I am getting from some TestFlight users now. In fact I am not seeing ANY CKERRORS for the two testers I have who are reporting the issue.... and yet not updating. ... By the way dude, thanks for the reply. Any other thoughts based on the below?!

  • So on the cloudkit console deploy schema changes was still available on the Development container. I don't understand that actually because I thought I read someplace that if the initialization code listed below is run then the Dev schema is deployed and that once an App runs on production using that schema that it automatically gets deployed to production? Someplace I developed a misconception. I used the deploy option and now I see the field on the production container. So THANKS!

Add a Comment

The CloudKit Console says the development schema and which has the field nameFirstChar field is indicated as deployed to production. However I DO NOT see it over on the production side. See the images. How is this possible and or what am I missing? The data is syncing just fine on all my devices and perhaps some users ... I think. And I ran this code at various points to deploy development to production:

    func initializeCloudKitSchemaForNewModel()
    {
        coreDataLogger.log("*** Initialize CloudKit Scheme for New Model - Start")
        if(!useiCloud) { return }
        do {
            // Use the container to initialize the development schema.
            let options = NSPersistentCloudKitContainerSchemaInitializationOptions()
            try pc.initializeCloudKitSchema(options:options)
        }
        catch {
            coreDataLogger.error("*** CoreDataUtil Initializing new schema: \(error)")
        }
        coreDataLogger.log("*** Initialize CloudKit Scheme for New Model - End")
    }