作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是我在 Business
实体的源模型中所拥有的:
这就是我在 Business
实体的目标模型中所拥有的:
如您所见,我将关系从多更改为一,从 users
更改为 user
。
但现在我有以下错误:
URL:file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite options:{ NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1;} ... returned error Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite, reason=Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship, destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170458990 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}}} with userInfo dictionary { NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134110 \"An error occurred during persistent store migration.\" UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}"; destinationURL = "file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3"; reason = "Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship"; sourceURL = "file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite";}fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite, reason=Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship, destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170458990 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}}}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.58.6/src/swift/stdlib/public/core/ErrorType.swift, line 1782016-11-30 14:25:43.070185 POSowner[3474:513840] fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite, reason=Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship, destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170458990 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}}}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.58.6/src/swift/stdlib/public/core/ErrorType.swift, line 178
而且我不知道该怎么做才能解决这个问题。有什么想法吗?
这就是我设置核心数据堆栈的方式:
static func mr_setupCoreDataStack() { guard NSPersistentStoreCoordinator.mr_default() == nil else { return } let managedObjectModel = NSManagedObjectModel.mr_default() let persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel!) var storePath = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: SharedGroupName) storePath = storePath!.appendingPathComponent("POSowner.sqlite") let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true] try! persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: storePath, options: options) NSPersistentStoreCoordinator.mr_setDefaultStoreCoordinator(persistentStoreCoordinator) NSManagedObjectContext.mr_initializeDefaultContext(with: persistentStoreCoordinator)}
最佳答案
最简单的解决方案是删除当前数据库并允许 MagicalRecord
创建一个新数据库而不进行任何迁移。请记住只一次。
static func mr_setupCoreDataStack() {
var storePath = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: SharedGroupName)
storePath = storePath!.appendingPathComponent("POSowner.sqlite")
try! FileManager.default.removeItem(at: storePath!)
}
关于ios - 当关系从多变为一时如何执行迁移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40889727/
我是一名优秀的程序员,十分优秀!