ios - 核心数据映射模型无法使用正确的哈希值

标签 ios core-data

所以我决定为我的一个实体创建 2 个子实体。

为了测试,我创建了这两个实体,没有任何属性,也没有关系。

如果我使用推断映射模型,核心数据会失败并且应用程序会崩溃。举报here

如果我创建映射模型,核心数据也无法升级。我检查了核心数据日志,它说实体哈希是正确的。 这里可能出了什么问题?

 CoreData: annotation: Incompatible version schema for persistent store
 'file://localhost/Users/.../StoreContent/persistentStore'.
 store metadata = {
     NSPersistenceFrameworkVersion = 419;
     NSStoreModelVersionHashes =     {
         Chat = <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>;
         Contact = <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>;
         Message = <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d>;
         User = <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>;
     };
     NSStoreModelVersionHashesVersion = 3;
     NSStoreModelVersionIdentifiers =     (
         3July13
     );
     NSStoreType = SQLite;
     NSStoreUUID = "73F77A17-9720-4D0E-90DD-D07A0EAECB29";
     "_NSAutoVacuumLevel" = 2; } and current model versions = {
     Broadcast = <e2afd25a 758f8e8b 7a2e1f2d 03042e32 e5e23693 a4935257 04a8e9fb 535e2452>;
     Chat = <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>;
     Contact = <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>;
     Group = <67fa7527 b68ea99d ee8e704f 30f20e48 58350963 73e29c19 8aea7604 dfac7d7c>;
     Message = <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d>;
     User = <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>; } 
2013-07-04 10:25:53.678 JonglaIM[90118:22103]
 CoreData: annotation: (migration)   will attempt automatic schema
 migration 2013-07-04 10:25:55.209 x[90118:22103] CoreData:
 annotation: (migration) looking for mapping model with   source
 hashes:  {
     Chat = <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>;
     Contact = <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>;
     Message = <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d>;
     User = <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>; }  
destination hashes: {
     Broadcast = <e2afd25a 758f8e8b 7a2e1f2d 03042e32 e5e23693 a4935257 04a8e9fb 535e2452>;
     Chat = <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>;
     Contact = <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>;
     Group = <67fa7527 b68ea99d ee8e704f 30f20e48 58350963 73e29c19 8aea7604 dfac7d7c>;
     Message = <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d>;
     User = <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>; } 
 2013-07-04 10:25:55.214 x[90118:22103]
 CoreData: annotation: (migration) checking mapping model at path
file://localhost/Users/.../Model.cdm
 source hashes:  {(
     <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>,
     <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>,
     <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>,
     <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d> )}  
destination hashes: {(
     <e2afd25a 758f8e8b 7a2e1f2d 03042e32 e5e23693 a4935257 04a8e9fb 535e2452>,
     <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>,
     <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>,
     <67fa7527 b68ea99d ee8e704f 30f20e48 58350963 73e29c19 8aea7604 dfac7d7c>,
     <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>,
     <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d> )} 2013-07-04 10:25:55.215 x[90118:22103] CoreData:
 annotation: (migration) no suitable mapping model found

最佳答案

现在已经是 2019 年了,撰写本文时 Xcode v10.2,这个问题仍然相关。

我向数据模型(在新版本中)添加了一个属性,并希望根据当前属性将一些数据迁移到其中,以确保在访问商店时它具有值。我创建了一个新的模型版本,添加了属性,然后使用自定义策略创建了实体映射文件来实现此目的。

在我把头撞到墙上一整天后,这里的说明强调了修复:https://blog.vucica.net/2013/04/core-data-migrating-ignores-manual-mapping-model-or-fails-migration-despite-mapping-models-existence.html

基本上,在 Xcode 映射模型编辑器中,交换“源”和“目标”模型,然后再次将它们切换回来。我通过在更改之前提交,然后观察之后对 xcmapping.xml 文件的细微更改来验证这实际上确实导致了更改。

这不是 Xcode 中的愚蠢错误第一次导致挫败感,而且可能也不会是最后一次。那好吧。继续前进!

关于ios - 核心数据映射模型无法使用正确的哈希值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17464414/

相关文章:

Swift - 核心数据中的一对多关系

ios - 多点连接发送和接收 NSManagedObject

iphone - 使用 CoreData 创建静态库时出现问题 - 无法使用 nil 模型创建 NSPersistentStoreCoordinator

ios - 带阴影的 UITableView

ios - MGLPolyLine 颜色更改不起作用 - Swift 4、Mapbox

ios - UIButton 在我不希望它是透明的时候是透明的

android - 具有离线和关系支持的跨平台同步解决方案

ios - Objective-C : Filtering based on location

java - 处理命令时发生未知的服务器端错误。原始错误 : Command failed: ideviceinstaller -u

iphone - 有没有办法为给定的 NSManagedObject 检索一组或一组键?