Issue with SwiftData: “no such table: ZAPPSETTINGS” and SQLite I/O error on app launch
Hello,
I’m encountering persistent errors with SwiftData in my SwiftUI app related to Core Data’s underlying SQLite database. Despite defining my models correctly, the app fails to initialize the persistent store, throwing the following error on startup:
CoreData error: SQLCore dispatchRequest: no such table: ZAPPSETTINGS. I/O error opening database at /.../default.store. SQLite error code:1, NSSQLiteErrorDomain=1. File “default.store” couldn’t be opened. Context The error only appears concerning my AppSettings model. I have another model, LocationPoint, which appears correctly defined and used. I have tried deleting the app, resetting the device, and cleaning builds but the error persists. The error message suggests the database file is present but the table for ZAPPSETTINGS (the Core Data table for AppSettings) does not exist. Code Samples Main App Entry
import SwiftData
import SwiftUI
@main
struct Krow3_0App: App {
@State private var userLocationManager = UserLocationManager()
@State private var geocodingViewModel = GeocodingViewModel()
@State private var locationSearchViewModel = LocationSearchViewModel()
@State private var router = Router()
var body: some Scene {
WindowGroup {
LaunchView()
.environment(userLocationManager)
.environment(geocodingViewModel)
.environment(locationSearchViewModel)
.environment(router)
.modelContainer(for: [LocationPoint.self, AppSettings.self])
}
}
}
AppSettings Model
import Foundation
import SwiftData
@Model
class AppSettings {
var isMetric: Bool
init(isMetric: Bool = false) {
self.isMetric = isMetric
}
}
What I’ve Tried Fully uninstalling and reinstalling the app on device and simulator. Resetting the simulator/device. Cleaning the Xcode build folder. Verifying the schema logs which correctly list both LocationPoint and AppSettings. Changing model names to avoid potential conflicts. Adding .modelContainer configuration with autosave enabled. Questions Is there a known bug or limitation with SwiftData concerning certain model setups or naming? Could this be related to how the data container initializes or migrates schemas? Are there recommended debugging or migration steps to resolve “no such table” SQLite errors with SwiftData? How can I safely reset or migrate the persistent store without corrupting the database? Any insights or suggestions would be greatly appreciated!
Thank you!