2011-04-01 120 views
18

这是我第一次使用核心数据,并且出现以下错误。核心数据;可可错误134100

如果你能告诉我如何解决它,我将非常感激。

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

回答

60

这里的原因:

The model used to open the store is incompatible with the one used to create the store 

而且这里是你如何做到了:

  1. 你创造了一些实体的某些属性,写了一些代码
  2. 推出的应用程序,可能添加了一些内容
  3. 退出应用程序,并添加/更改一些实体属性
  4. 你可能会再次启动了程序,现在它给你的错误

这样做的原因是因为您的新托管对象模型试图使用较旧版本的存储(首次启动应用时创建的那个版本)。

快速和肮脏的修复将删除存储文件(〜/库/应用程序支持/ YOUR_APP /中的某处)并再次启动您的应用程序。

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

+2

我在一个由两人组成的团队中工作 - 当我们其中一个人安装到手机上,其中的应用程序先前已安装到另一个手机中时,我们得到此错误。数据模型/结构没有改变。这与签名应用程序的用户身份有关吗? – Marc 2012-05-15 10:34:55

+0

不知道那个。它可能会受到应用程序的GUID的影响。 – Eimantas 2012-05-15 10:40:22

+0

奇怪 - 我们使用SVN作为版本控制。我担心如果另一个开发人员在我之后接管应用程序,他们可能会在这次崩溃时将应用程序发布到应用商店。如果我找出它发生的原因,将会保持这个线程。 – Marc 2012-05-16 08:11:04

14

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

您不必更改项目中的文件(除了选择当前模型并使用菜单替换类:编辑器/创建NSManaged对象子类)。

1

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

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

+0

我该如何以编程方式进行此操作,例如当我复制了UIManagedDocument并且想要使用它的副本时? – AlexR 2013-07-07 15:42:15

2

你应该做以下步骤

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

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

- (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

+0

将iOS从10.3升级到10.3.2后出现问题。这有助于解决问题。谢谢! – 2017-06-18 12:49:47