我正在尝试像这样迁移db -
NSError *error = nil;
NSMappingModel *mapping = [NSMappingModel inferredMappingModelForSourceModel: oldModel destinationModel: self error: &error];
NSString *newContextPath = [contextPath stringByAppendingPathExtension: @"tmp"];
NSValue *classValue = [[NSPersistentStoreCoordinator registeredStoreTypes] objectForKey: NSSQLiteStoreType];
Class sqliteStoreClass = (Class)[classValue pointerValue];
Class sqliteStoreMigrationManagerClass = [sqliteStoreClass migrationManagerClass];
NSMigrationManager *manager = [[sqliteStoreMigrationManagerClass alloc] initWithSourceModel: oldModel destinationModel: self];
@try {
if (![manager migrateStoreFromURL: srcURL type:NSSQLiteStoreType options:nil withMappingModel:mapping toDestinationURL: dstURL destinationType:NSSQLiteStoreType destinationOptions:nil error:&error]) {
LOG(@"Migration failed %@", error);
return NO;
}
} @catch (NSException *exception) {
LOG(@"Exception: %@", exception);
return NO;
}
if (![[NSFileManager defaultManager] removeItemAtPath: contextPath error: &error]) {
return NO;
}
if (![[NSFileManager defaultManager] moveItemAtPath: newContextPath toPath: contextPath error: &error]) {
return NO;
}
当我尝试将当前模型写入db时,我收到此错误, libsqlite3.dylib的客户端BUG:数据库完整性受API违规影响:vnode在使用时取消链接: 虽然它已成功迁移。当我尝试访问迁移的数据库时,它说它已损坏或格式错误并崩溃。不确定我做错了什么。一切正常,在iOS 10中仍能正常工作。仅在iOS11中发生。
感谢任何帮助。谢谢!