【问题标题】:Core Data; Cocoa error 134100核心数据;可可错误 134100
【发布时间】:2011-07-27 21:22:46
【问题描述】:

这是我第一次使用核心数据,我收到以下错误。

如果您能告诉我如何解决它,我将不胜感激。

Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x5927880 {metadata=<CFBasicHash 0x59269a0 [0x1007400]>{type = immutable dict, count = 7,
entries =>
    2 : <CFString 0x5926e10 [0x1007400]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x5927240 [0x1007400]>{type = immutable, count = 0, values = ()}
    4 : <CFString 0x5927190 [0x1007400]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x5926ca0 [0x1007400]>{value = +320, type = kCFNumberSInt64Type}
    6 : <CFString 0x59271c0 [0x1007400]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x5927340 [0x1007400]>{type = immutable dict, count = 2,
entries =>
    0 : <CFString 0x5927280 [0x1007400]>{contents = "Details"} = <CFData 0x59272f0 [0x1007400]>{length = 32, capacity = 32, bytes = 0x434e180241ecf461e59580e640ff926b ... aa456d1410ed9d1b}
    2 : <CFString 0x5927260 [0x1007400]>{contents = "History"} = <CFData 0x59272a0 [0x1007400]>{length = 32, capacity = 32, bytes = 0x3437f77a5563363f66b9d72ea76e0ff1 ... be194eb9dd17cddc}
}

    7 : <CFString 0xe238b0 [0x1007400]>{contents = "NSStoreUUID"} = <CFString 0x5926fc0 [0x1007400]>{contents = "6C5FECCB-0B64-46EB-809B-E0A4577D1E90"}
    8 : <CFString 0xe23720 [0x1007400]>{contents = "NSStoreType"} = <CFString 0xe238f0 [0x1007400]>{contents = "SQLite"}
    9 : <CFString 0x59271f0 [0x1007400]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0x4d13e20 [0x1007400]>{value = +3, type = kCFNumberSInt32Type}
    10 : <CFString 0x5927220 [0x1007400]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x5927380 [0x1007400]>{contents = "2"}
}
, reason=The model used to open the store is incompatible with the one used to create the store}, {
    metadata =     {
        NSPersistenceFrameworkVersion = 320;
        NSStoreModelVersionHashes =         {
            Details = <434e1802 41ecf461 e59580e6 40ff926b 20004ce9 58eb965f aa456d14 10ed9d1b>;
            History = <3437f77a 5563363f 66b9d72e a76e0ff1 ed7f70fd cb7035e9 be194eb9 dd17cddc>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
        );
        NSStoreType = SQLite;
        NSStoreUUID = "6C5FECCB-0B64-46EB-809B-E0A4577D1E90";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "The model used to open the store is incompatible with the one used to create the store";
}
sharedlibrary apply-load-rules all
Current language:  auto; currently objective-c
kill
quit
Program ended with exit code: 0

我的代码在这里: https://gist.github.com/898579

【问题讨论】:

    标签: iphone objective-c xcode core-data ios4


    【解决方案1】:

    这也发生在我身上,通过删除 STORE URL,我用下面的代码修复了这个问题 - [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

    澄清: 如果我们不希望数据在测试之间停留,请删除 storeURL 中的文件并重新创建它。由于新测试有新模型版本,旧文件无法正常打开。 此外,如果我们更改托管对象模型 - 我们必须为其编写迁移。

    【讨论】:

      【解决方案2】:

      原因如下:

      开店的型号和开店的型号不兼容

      你是这样做的:

      1. 您创建了一些具有某些属性的实体并编写了一些代码
      2. 启动应用,可能添加了一些内容
      3. 退出应用并添加/更改更多具有属性的实体
      4. 您可能再次启动了该应用程序,但现在它给了您错误

      这是因为您的新托管对象模型正在尝试使用旧版本的存储(启动应用时第一次创建的存储)。

      快速而肮脏的解决方法是删除存储文件(在 ~/Library/Application Support/YOUR_APP/ 中的某个位置)并再次启动您的应用。

      为了将来参考 - 如果您发布了一个应用,并且在下一个版本中该应用更改了托管对象模型 - 您必须为其编写迁移。 Apple 文档中的核心数据编程食谱涵盖了所有这些以及更多内容。

      【讨论】:

      • 我在两个人的团队中工作 - 当我们中的一个人安装到之前安装了应用程序的手机上时,我们会收到此错误。数据模型/结构没有改变。这与签署应用程序的用户的身份有关吗?
      • 不知道那个。它可能会受到应用的 GUID 的影响。
      • 奇怪 - 我们使用 SVN 作为版本控制。我担心如果其他开发人员在我之后接管该应用程序,他们可能会在这次崩溃时发布到应用程序商店。如果我发现它发生的原因,将保持发布此线程。
      • 完美!感谢您的解决方案。我已经删除了旧数据库,现在一切正常!
      【解决方案3】:

      如果您处于开发模式并且不想在每次更改实体时都删除应用程序,我建议使用此解决方案:

      - (void)removeCoreDataStorage {
          // Where does the SQLite file go?
          NSArray *documentDirectories =
          NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                              NSUserDomainMask,
                                              YES);
          // Get one and only document directory from that list
          NSString *documentDirectory = [documentDirectories firstObject];
          NSString *path = [documentDirectory stringByAppendingPathComponent:@"model.sqlite"];
      
          NSError *error = nil;
          NSURL *storeURL = [NSURL fileURLWithPath:path];
      
          NSURL *storeURLWal = [NSURL URLWithString:[storeURL.absoluteString stringByReplacingOccurrencesOfString:@".sqlite" withString:@".sqlite-wal"]];
          NSURL *storeURLShm = [NSURL URLWithString:[storeURL.absoluteString stringByReplacingOccurrencesOfString:@".sqlite" withString:@".sqlite-shm"]];
      
          BOOL isRemoveItemAtURL = [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
          if (isRemoveItemAtURL == NO) {
              NSLog(@"NO RemoveItemAtURL. Reason: %@", error.localizedFailureReason);
          }
      
          BOOL isRemoveItemAtURLWal = [[NSFileManager defaultManager] removeItemAtURL:storeURLWal error:&error];
          if (isRemoveItemAtURLWal == NO) {
              NSLog(@"NO RemoveItemAtURL. Reason: %@", error.localizedFailureReason);
          }
      
          BOOL isRemoveItemAtURLShm = [[NSFileManager defaultManager] removeItemAtURL:storeURLShm error:&error];
          if (isRemoveItemAtURLShm == NO) {
              NSLog(@"NO RemoveItemAtURL. Reason: %@", error.localizedFailureReason);
          }
      }
      

      别忘了用你自己的路径更改path

      【讨论】:

      • iOS从10.3升级到10.3.2后出现问题。这有助于解决问题。谢谢!
      【解决方案4】:

      您应该执行以下步骤

      1. 删除应用程序并再次运行它,如果它仍然显示相同的错误。那么这意味着,您使用了不同类型的特定属性/属性。
      2. 转到您的 .xcdatamodeled 文件并检查每个属性的类型。
      3. 转到您的代码并检查,在核心数据中插入属性/对象时,您使用了相同类型的不同。因此,关键是代码中属性/对象的 type(NSString, NSDate...) 和 .xcdatamodeled 应该相同。如果不是,则会给出错误“Error Domain=NSCocoaErrorDomain Code=134100”

      【讨论】:

        【解决方案5】:

        有时您需要从另一个应用程序创建的存储中加载数据 - 例如。一个应用程序仅用于从外部源加载数据并保存到商店中,而另一个应用程序则使用这个充满数据的商店作为起点。

        我不想说它是超级正确的,但如果您在应用程序开发过程中不时需要它:只需将商店中的 UUID(通过 SQLVue 等)更改为预期的正确值通过您的应用程序。在大多数情况下,您会在名为 ZMETADATA 的表中找到唯一的一列 Z_UUID 中的 UUID。但请记住 - 只是为了快速调试/开发目的。不要以编程方式使用它。

        【讨论】:

        • 我将如何以编程方式执行此操作,例如当我复制了 UIManagedDocument 并想使用它的副本时?
        【解决方案6】:

        如果您从模拟器/设备中删除该应用程序就足够了。

        您不必更改项目中的文件(除了选择当前模型并使用菜单替换类:Editor/Create NSManaged Object Subclass)。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-01-20
          • 1970-01-01
          • 2011-10-30
          • 2014-07-05
          • 2012-03-28
          • 2012-02-16
          • 2010-12-19
          相关资源
          最近更新 更多