我最近对我的Core Data模型文件进行了一些更改,并尝试执行轻量级迁移。我之前已经使用过轻量级迁移,所以我知道我已经正确完成了所有设置。
我唯一的问题是我改变了一种关系的类型:它曾经是To-One,现在它是To-Many。根据Apple的文档,在这种情况下,轻量级迁移应该可以正常工作,但是当我运行代码并且系统开始迁移数据时,会发生崩溃。
我注意到在堆栈跟踪中,以下方法导致崩溃:
3 CoreData 0x008df2d1 -[_NSSQLEntityMigrationDescription
_populateSQLValuesForDestinationToOne:fromSourceToOne:] + 145
因此,由于某种原因,被调用的方法试图将关系迁移,就像它仍然是To-One关系一样。
为什么映射模型的推断不正确,我该如何解决?
谢谢!
修改
这是我收到的错误消息:
*** 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
答案 0 :(得分:0)
轻量级(或自动)迁移确实支持将关系从一对一更改为一对多。
几个步骤:
xcdatamodel
)NSSet
)s
)。轻量级迁移器将基于它创建映射。
与重命名实体等相同。