【发布时间】:2018-11-14 05:00:41
【问题描述】:
我最近对我的核心数据模型文件进行了一些更改,并且我正在尝试执行轻量级迁移。我之前已经使用过轻量级迁移,所以我知道我正确地完成了所有设置。
我唯一的问题是我改变了关系的类型:它曾经是 To-One,现在是 To-Many。根据 Apple 的文档,轻量级迁移在这种情况下应该可以正常工作,但是当我运行代码并且系统开始迁移数据时,会发生崩溃。
我在堆栈跟踪中注意到以下方法导致崩溃:
3 CoreData 0x008df2d1 -[_NSSQLEntityMigrationDescription
_populateSQLValuesForDestinationToOne:fromSourceToOne:] + 145
因此,由于某种原因,被调用的方法试图迁移关系,就好像它仍然是一对一的关系一样。
为什么映射模型被错误推断,我该如何解决?
谢谢!
编辑
这是我收到的错误消息:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** setObjectForKey: object cannot be nil (key: Z8CUSCONNECTION)'
cusConnection 是我从 To-One 更改为 To-Many 的关系名称。
另外,这里是堆栈跟踪:
0 CoreFoundation 0x01588746 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01211a97 objc_exception_throw + 44
2 CoreFoundation 0x01479c9c -[__NSDictionaryM setObject:forKey:] + 940
3 CoreData 0x009182d1 -[_NSSQLEntityMigrationDescription _populateSQLValuesForDestinationToOne:fromSourceToOne:] + 145
4 CoreData 0x00918d30 -[_NSSQLEntityMigrationDescription _populateSQLValuesForVirtualToOnesWithMigrationContext:] + 1648
5 CoreData 0x00918202 -[_NSSQLEntityMigrationDescription _generateSQLValueMappingsWithMigrationContext:] + 962
6 CoreData 0x0091998b -[_NSSQLEntityMigrationDescription sqlValueForColumnName:migrationContext:] + 59
7 CoreData 0x00923cf1 -[_NSSQLTableMigrationDescription createInsertStatementForEntityMigration:migrationContext:] + 689
8 CoreData 0x00922d07 -[_NSSQLTableMigrationDescription appendStatementsToPerformMigration:migrationContext:] + 1143
9 CoreData 0x0091d024 -[_NSSQLiteStoreMigrator createEntityMigrationStatements] + 900
10 CoreData 0x0091b088 -[_NSSQLiteStoreMigrator performMigration:] + 104
11 CoreData 0x0092753a -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 1962
12 CoreData 0x008b9104 -[NSMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 692
13 CoreData 0x00908605 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 341
14 CoreData 0x009074b5 -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:] + 117
15 CoreData 0x00909380 -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 3136
16 CoreData 0x008c2c76 __91-[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:]_block_invoke + 5270
17 CoreData 0x008d12ff gutsOfBlockToNSPersistentStoreCoordinatorPerform + 191
18 libdispatch.dylib 0x03593bef _dispatch_client_callout + 14
19 libdispatch.dylib 0x03576b0d _dispatch_barrier_sync_f_invoke + 144
20 libdispatch.dylib 0x0357623f dispatch_barrier_sync_f + 105
21 CoreData 0x008c03f7 _perform + 183
22 CoreData 0x007b272c -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 236
23 Nimbus II 0x00117fd2 -[AppDelegate persistentStoreCoordinator] + 674
24 Nimbus II 0x002c79b6 +[UserInformationParser saveData:] + 374
25 Nimbus II 0x001c2f2e __47-[SynchronizationController synchronizeData]_block_invoke + 366
26 libdispatch.dylib 0x035715ea _dispatch_call_block_and_release + 15
27 libdispatch.dylib 0x03593bef _dispatch_client_callout + 14
28 libdispatch.dylib 0x0357b1ef _dispatch_root_queue_drain + 1092
29 libdispatch.dylib 0x0357cb70 _dispatch_worker_thread3 + 115
30 libsystem_pthread.dylib 0x038d843e _pthread_wqthread + 1050
31 libsystem_pthread.dylib 0x038d5f72 start_wqthread + 34
【问题讨论】:
-
您应该发布整个崩溃,而不是只发布一行。调试控制台中显示的错误以及完整堆栈将有助于诊断问题。
-
@marcus-s-zarra 就是这样:-)
-
映射模型是Core Data生成的吗?
-
@Willeke 是的。自动轻量级迁移
-
@Diego 我刚刚遇到了完全相同的问题(在 iOS 9 上)。你最后找到解决办法了吗?还是您最终只是使用了自定义(非轻量级)迁移?
标签: ios xcode core-data database-migration