SwiftData multiple Models - Thread 1: "NSFetchRequest could not locate an NSEntityDescription for entity name 'PastTripData'"

It works fine if I take either model out, but it doesn't work with both I have tried multiple variations

import SwiftData
import Foundation

@main
struct blendTravelfourApp: App {
    
    @Environment(\.modelContext) var context

    var body: some Scene {
        WindowGroup {
            ContentView()
                .modelContainer(for: PlanTripData.self)
                .modelContainer(for: PastTripData.self)
        }
    }
}
import SwiftData


@main
struct blendTravelfourApp: App {
    var container: ModelContainer

    init() {
        do {
            let config1 = ModelConfiguration(for: PlanTripData.self)
            let config2 = ModelConfiguration(for: PastTripData.self)

            container = try ModelContainer(for: PlanTripData.self, PastTripData.self, configurations: config1, config2)
        } catch {
            fatalError("Failed to configure SwiftData container.")
        }
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
                .modelContainer(container)
        }
    }
}

I have the same exact issue and I've tried the same exact code that you've tried so it seems to be a SwiftUI bug. I've reported it to Apple.

I also found other threads about the same issue. Someone mentioned that the bug was resolved in iOS 17.4 Beta 2, but that wasn't the case for me. I still get the same crash + error.

Hi, I think it could work like this:

var body: some Scene {
    WindowGroup {
        ContentView()
    }
    .modelContainer(for: [PlanTripData.self, PastTripData.self])
}
SwiftData multiple Models - Thread 1: "NSFetchRequest could not locate an NSEntityDescription for entity name 'PastTripData'"
 
 
Q