This only happens on the preview right? For a good explanation: https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-54-crash-in-preview-of-swiftdata/26510/27172
TLDR; in the preview you're not initializing the container, so you'll need to:
#Preview {
ContentView()
.modelContainer(for: Student.self)
}
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: