I have a CoreData model with two entities, 'User' and 'Player', that both use 'Person' as their 'Parent Entity'. While the App appears to work correctly in the simulator, including with CloudKit via NSPersistentCloudKitContainer, I get a crash in Xcode Previews:
libswiftCore.dylib [
AGScoringModel/Persistence.swift:183: Fatal error: #init(inMemory:): Failed to load persistent stores:Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///Users/ebg/Library/Developer/.../CoreDataStores/private/database.sqlite, reason=Cannot migrate store in-place: Cannot merge multiple root entity source tables into one destination entity root table, destinationURL=file:///Users/ebg/Library/Developer/.../CoreDataStores/private/database.sqlite, NSUnderlyingError=0x600000ce02a0 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={message=Cannot merge multiple root entity source tables into one destination entity root table, destinationRootEntity=Person, NSUnderlyingException=Cannot merge multiple root entity source tables into one destination entity root table, sourceRootEntities=(
User,
Player
), reason=Cannot merge multiple root entity source tables into one destination entity root table}}}
]
Why is this? Something in my configuration for persistent container?
Based on the error alone it seems that you have an old database schema stored on disk, which cannot be migrated with an automatic migration to your current schema (there are many reasons the lightweight/automatic schema migration might fail, I'll link to some documentation below). You can delete the simulators that Previews uses by running the following command: xcrun simctl --set previews delete all
. That should clear any persistent data causing problems in your previews.
You might also consider setting up your persistent store to run in memory when you are using previews. This will help you to avoid such issues in the future.
You can read more about migrations in the documentation: