Load issue on SwiftData model container on macOS and not iOS

Hi,

I am developing a multi platform application using SwiftData. Since a few days, when running the macOS version I cannot create the model container while on iOS everything is fine.

On macOS I receive the error : Thread 1: Fatal error: Could not create ModelContainer: SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer) The code that initialize the model container is :

        let schema = Schema([
            Account.self,
            ABCategory.self
        ])
        let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)

        do {
            let container = try ModelContainer(for: schema, configurations: [modelConfiguration])
            container.mainContext.undoManager = UndoManager()
            return container
        } catch {
            fatalError("Could not create ModelContainer: \(error)")
        }
    }

    var body: some Scene {
        WindowGroup {
            ContentView(accuBalanceModel: accuBalanceModel)
        }
        .modelContainer(sharedModelContainer)
        //.modelContainer(for: [Account.self, ABCategory.self], inMemory: false, isUndoEnabled: true)
        
        #if os (OSX)
        //
        // Remove the 'New Window' menu item.
        //
        .commands {
            CommandGroup(replacing: CommandGroupPlacement.newItem) {
            }
        }
        #endif        
    }

I can say that the model has no issues as it works when running on IOS and also, if I change inMemory: false with inMemory: true the macOS version succeed in creating the model.

I can also say this is not a network issue as the Mac and the iOS device running the application are connected to the same box.

The Xcode version is Version 15.2 (15C500b) Ios device where everything is fine : iPhone 11 OS 17.3.1 (21D61) the Mac device : Mac mini M1 2020 : 14.0 (23A344)

Any advice to resolve that problem would be greatly appreciated.

Best Regards

Christophe Lestrade

Answered by Chris Tof in 783597022

Found the reason why.

I had a locally cached database that was in conflict with the model (I changed the type of an attribute). I removed the cache as explained here and that fixed the issue

Accepted Answer

Found the reason why.

I had a locally cached database that was in conflict with the model (I changed the type of an attribute). I removed the cache as explained here and that fixed the issue

Load issue on SwiftData model container on macOS and not iOS
 
 
Q