0

My app's database uses CoreData + CloudKit, but I want to remove CloudKit and use only local CoreData.

I run the app after replacing NSPersistentCloudKitContainer to NSPersistentContainer, but failed to load persistant stores.

How to result this problem ?

 lazy var persistentContainer: NSPersistentContainer = {
        let container = NSPersistentContainer(name: name)
        container.loadPersistentStores { _, error in
            if let error = error {
                fatalError("Unable to load persistent stores: \(error)")
            }
       }
       return container
    }()
Error Domain=NSCocoaErrorDomain Code=134110 "永続ストアの移行中にエラーが起きました。" 
UserInfo={
  sourceURL=file:///Users/junya/Library/Developer/CoreSimulator/Devices/14670F13-60FF-4F9E-A714-0A8AB2329C2D/data/Containers/Data/Application/CD56521D-D435-4938-AE7A-AD5F7D6FF44C/Library/Application%20Support/MyAppModel.sqlite, 
  reason=Cannot migrate store in-place: near "null": syntax error,
  destinationURL=file:///Users/junya/Library/Developer/CoreSimulator/Devices/14670F13-60FF-4F9E-A714-0A8AB2329C2D/data/Containers/Data/Application/CD56521D-D435-4938-AE7A-AD5F7D6FF44C/Library/Application%20Support/MyAppModel.sqlite, 
  NSUnderlyingError=0x600003c31b90 {
   Error Domain=NSCocoaErrorDomain Code=134110 "永続ストアの移行中にエラーが起きました。" 
  UserInfo={
   reason=near "null": syntax error, 
   NSSQLiteErrorDomain=1, 
   NSUnderlyingException=near "null": syntax error
   }
 }
}
junya
  • 1
  • You ought do a migration of your persistent store. In case your app is not yet shipped and just in a development phase my suggestion is to avoid it and just erase it from your simulator/device. Otherwise you’ll need to learn about migrating a CoreData store from one model version to another manually. – valeCocoa Jul 09 '22 at 17:26
  • Thanks for your kind reply. Unfortunately MyApp is already released to AppStore. Do you mean that migration is MyAppModel.xcdatamodel to MyAppModel.xcdatamodel2 ? I already try to update .xcdatamodel, but could not avoid error. maybe, I think some kind of procedure for migration lack. However, I don't know what else I should do. Could you let me know specific step ? – junya Jul 10 '22 at 05:55
  • Yes your model needs a mapping between the two versions in this case cause it’s not something that can be done automatically as it happens with simpler modifications (just adding a new entity, modifying one relationship, etc.). PS It’s very strange though the path you’re taking, cause usually you want to add iCloud syncing to an app model. What is gonna happen to users of your app relying on that data syncing between their devices? – valeCocoa Jul 11 '22 at 07:29

0 Answers0