Reputation: 333
In new version I start using Core Data. But when I try to migrate from an old database to the new one, I'm getting an error:
let dbName = "db.sqlite:"
guard let modelURL = Bundle.main.url(forResource: "Ex", withExtension: "momd"),
let model = NSManagedObjectModel(contentsOf: modelURL) else {
fatalError("model not found")
}
let psc = NSPersistentStoreCoordinator(managedObjectModel: model)
let databaseUrl = URL.defaultUrl.appendingPathComponent(dbName)
do {
try psc.addPersistentStore(ofType: NSSQLiteStoreType,
configurationName: nil,
at: databaseUrl,
options: [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true])
} catch {
fatalError("database migration error")
}
context = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
context.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy
context.persistentStoreCoordinator = psc
Error message:
Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={NSUnderlyingException=I/O error for database at /var/mobile/Containers/Data/Application/dsdasda-6Basdsd9C-4AE9-sad-sd/Documents/db.sqlite. SQLite error code:1, 'no such table: Z_METADATA', NSSQLiteErrorDomain=1} error: The file couldn’t be opened.
How i can resolve that?
Upvotes: 0
Views: 358
Reputation: 23400
The trailing colon in the dbName
looks extraneous. ("db.sqlite**:**")
Upvotes: 0