没有找到适合核心数据迁移的映射模型 [英] No suitable mapping model found for core data migration

查看:18
本文介绍了没有找到适合核心数据迁移的映射模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行需要 MappingModel 的 iOS 核心数据迁移.核心数据由于某种原因无法使用映射模型,它会退回到自动轻量级迁移.

I'm trying to perform an iOS Core Data migration that requires a MappingModel. Core data is not able to use the mapping model for some reason and it falls back to an automatic lightweight migration.

我启用了 MigrationDebug 选项以获取更多信息,但我看到的内容毫无意义.映射模型的源和目标哈希与源和目标 ManagedObjectModel 相同,忽略顺序.似乎应该使用映射模型,但日志显示找不到合适的映射模型".

I enabled the MigrationDebug option to get more info and what I see makes no sense. The source and destination hashes of the mapping model are identical, ignoring order, to the source and destination ManagedObjectModels. It seems like the mapping model should be used but the log says "no suitable mapping model found".

这是(省略的)日志:

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: ...

推荐答案

Xcode 4 生成的映射模型不会产生迁移所需的正确哈希值.您可以使用以下代码将迁移日志的输出与映射文件的哈希值进行比较:

The mapping model generated by Xcode 4 does not produce the correct hashes needed for the migration to occur. You can compare the output from the migration log to your mapping file's hashes with the code below:

    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);
    }

您会看到这些与迁移日志输出中的哈希值不匹配.

You'll see that these do not match the hashes in the migration log output.

解决方法是在 Xcode 5 中生成映射文件.

The workaround is to generate the mapping file in Xcode 5.

这篇关于没有找到适合核心数据迁移的映射模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆