Joh*_*ews 10 migration core-data ios
我正在尝试执行需要MappingModel的iOS核心数据迁移.由于某种原因,核心数据无法使用映射模型,而是回退到自动轻量级迁移.
我启用了MigrationDebug选项以获取更多信息,我看到的内容毫无意义.映射模型的源哈希值和目标哈希值与源和目标ManagedObjectModels相同,忽略顺序.似乎应该使用映射模型,但日志显示"找不到合适的映射模型".
这是(省略)日志:
CoreData: annotation: (migration) will attempt automatic schema migration
CoreData: annotation: (migration) looking for mapping model with
source hashes:
{
TSBaseEntity = <4797118c 50068f2f f544d9a9 4884720b 55ec7e4d 0d4c8f4e 1ee44be3 b06d2edc>;
TSBuyer = <91e837d1 3f348913 eff634d6 6fb9b3a6 747e2390 fbdc4ae6 32cc56d6 7582d4a8>;
...
}
destination hashes: {
TSBaseEntity = <4797118c 50068f2f f544d9a9 4884720b 55ec7e4d 0d4c8f4e 1ee44be3 b06d2edc>;
TSBuyer = <e316a857 8919c4be eef15387 5c67a21b 67d32919 99ead438 1ff93c05 2e065fcc>;
...
}
CoreData: annotation: (migration) checking mapping model at path file://localhost/Users/xandrews/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/0A84951E-21FC-47C0-A1B7-F880ACB672C4/Dev.app/Migrate_0_5_24To_0_5_27.cdm
source hashes:
{(
<4797118c 50068f2f f544d9a9 4884720b 55ec7e4d 0d4c8f4e 1ee44be3 b06d2edc>,
<91e837d1 3f348913 eff634d6 6fb9b3a6 747e2390 fbdc4ae6 32cc56d6 7582d4a8>,
...
)}
destination hashes: {(
<4797118c 50068f2f f544d9a9 4884720b 55ec7e4d 0d4c8f4e 1ee44be3 b06d2edc>,
<e316a857 8919c4be eef15387 5c67a21b 67d32919 99ead438 1ff93c05 2e065fcc>,
...
)}
CoreData: annotation: (migration) no suitable mapping model found
CoreData: annotation: (migration) inferring a mapping model between data models with
source hashes: ...
Run Code Online (Sandbox Code Playgroud)
Xcode 4生成的映射模型不会产生迁移发生所需的正确哈希值.您可以使用以下代码将迁移日志的输出与映射文件的哈希值进行比较:
NSString *mappingModelPath = [[NSBundle mainBundle] pathForResource:@"MappingFile" ofType:@"cdm"];
NSMappingModel *mappingModel = [[NSMappingModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:mappingModelPath]];
for (NSEntityMapping *entityMapping in mappingModel.entityMappings) {
NSLog(@"%@: %@", entityMapping.sourceEntityName, entityMapping.sourceEntityVersionHash);
NSLog(@"%@: %@", entityMapping.destinationEntityName, entityMapping.destinationEntityVersionHash);
}
Run Code Online (Sandbox Code Playgroud)
您将看到这些与迁移日志输出中的哈希值不匹配.
解决方法是在Xcode 5中生成映射文件.
归档时间: |
|
查看次数: |
2737 次 |
最近记录: |