如何恢复丢失的 CoreData 模型版本?
How can I restore a CoreData Model version that has gone missing?
所以,我搞砸了。我在 Xcode 中创建了现有 CoreData 模型的新版本,但不知何故从未最终提交 .xcdatamodel
文件(或更准确地说,是其中的 contents
文件)。现在,过了一会儿,该文件丢失了,我无法恢复它。尝试打开 xcode 中的 xcdatamodel 文件时出现错误 "The file "contents" could be opened because there is no such file".
我想我可以聪明地从以前的版本 .xcdatamodel
文件中复制 contents
文件,然后添加回我为这次迁移添加的 table (幸运的是,我只添加了一个 table 并生成了一个 class,因此再次创建 table 很容易)。问题是,当我 运行 模拟器或数据已经存在的设备上的应用程序时,我收到以下错误:Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)"
该错误还列出了 NSPersistentStoreCoordinator 的当前模型哈希值,因此现在我假设所讨论模型的哈希值可能不同。
我在这里有哪些选择?如何修复数据,使用户不必卸载应用程序并在更新前丢失所有数据?
错误的完整内容如下:
2015-01-21 11:01:11.050 Marq[2699:607] CoreData: annotation: Incompatible version schema for persistent store 'file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite'. store metadata = {
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
} and current model versions = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <cb0da8d0 a2c307de 53600c9c 214dfeab bcefc9f0 0507f6e6 1b8ef683 ef608349>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <b9da47a0 bdaf3956 5e75039f e3429a42 bf34d642 871c2f6d 7da7edfa f5380634>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
}
2015-01-21 11:01:11.055 Marq[2699:607] CoreData: annotation: (migration) will attempt automatic schema migration
2015-01-21 11:01:11.335 Marq[2699:607] CoreData: error: (migration) migration failed with error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x6b58f220 {URL=file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite, metadata={
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store}
Error User Info: {
URL = "file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite";
metadata = {
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
};
reason = "Can't find model for source store";
}
2015-01-21 11:01:11.340 Marq[2699:607] -[AISDataService persistentStoreCoordinator] line 1410 $ Unresolved error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x6b58f220 {URL=file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite, metadata={
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store}, {
URL = "file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite";
metadata = {
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
};
reason = "Can't find model for source store";
}
您应该可以通过核心数据迁移来解决这个问题:http://www.raywenderlich.com/27657/how-to-perform-a-lightweight-core-data-migration
您在尝试重新创建丢失的版本时遇到的错误几乎可以肯定是因为您没有以完全相同的方式重新创建它。如果您不确定,最简单的方法就是再试一次。如果您创建的新文件与旧文件 完全 匹配,那么它没有理由不工作。
如果您不能这样做,您可以使用以下方法从应用程序的应用商店副本恢复模型:
如果您从 Xcode 存档(.xcarchive
)开始,那只是一个包含应用程序包和一些其他内容的文件包。浏览它以找到包含 all 核心数据模型的 momd
,然后查看该包内部以找到与您缺少的版本匹配的单个 mom
。将该文件复制到存档之外的某个位置。
如果您从 ipa
开始,那只是一个包含该应用程序的 zip 文件。用任何你喜欢的解压工具解压它,然后按照上面的步骤找到正确的 mom
.
mom
文件是编译后的模型,但与源码不同的是,模型编译是可以逆向的。在 Xcode 中创建一个新的模型版本并删除其中的 所有内容 以便它完全为空。然后转到编辑器菜单和select导入...。导入您在上面找到的 mom
文件。
您现在应该拥有一个与您的应用中的编译模型完全对应的 Core Data 模型版本。 将它提交到您的源代码存储库,以便下次使用。
所以,我搞砸了。我在 Xcode 中创建了现有 CoreData 模型的新版本,但不知何故从未最终提交 .xcdatamodel
文件(或更准确地说,是其中的 contents
文件)。现在,过了一会儿,该文件丢失了,我无法恢复它。尝试打开 xcode 中的 xcdatamodel 文件时出现错误 "The file "contents" could be opened because there is no such file".
我想我可以聪明地从以前的版本 .xcdatamodel
文件中复制 contents
文件,然后添加回我为这次迁移添加的 table (幸运的是,我只添加了一个 table 并生成了一个 class,因此再次创建 table 很容易)。问题是,当我 运行 模拟器或数据已经存在的设备上的应用程序时,我收到以下错误:Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)"
该错误还列出了 NSPersistentStoreCoordinator 的当前模型哈希值,因此现在我假设所讨论模型的哈希值可能不同。
我在这里有哪些选择?如何修复数据,使用户不必卸载应用程序并在更新前丢失所有数据?
错误的完整内容如下:
2015-01-21 11:01:11.050 Marq[2699:607] CoreData: annotation: Incompatible version schema for persistent store 'file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite'. store metadata = {
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
} and current model versions = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <cb0da8d0 a2c307de 53600c9c 214dfeab bcefc9f0 0507f6e6 1b8ef683 ef608349>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <b9da47a0 bdaf3956 5e75039f e3429a42 bf34d642 871c2f6d 7da7edfa f5380634>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
}
2015-01-21 11:01:11.055 Marq[2699:607] CoreData: annotation: (migration) will attempt automatic schema migration
2015-01-21 11:01:11.335 Marq[2699:607] CoreData: error: (migration) migration failed with error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x6b58f220 {URL=file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite, metadata={
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store}
Error User Info: {
URL = "file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite";
metadata = {
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
};
reason = "Can't find model for source store";
}
2015-01-21 11:01:11.340 Marq[2699:607] -[AISDataService persistentStoreCoordinator] line 1410 $ Unresolved error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x6b58f220 {URL=file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite, metadata={
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store}, {
URL = "file:///Users/aerion/Library/Developer/CoreSimulator/Devices/71815540-57DE-49BF-A6F6-69500A54281F/data/Applications/EE5B15A6-A5ED-46EB-9DFD-B6B54353E35B/Documents/ARUPInspect_Schema.sqlite";
metadata = {
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
Asset = <4b2b421f 4295c02f 89b5a2e8 1c4fc3e9 2b515eca 95e89ad6 e65c891d f82b1090>;
BooleanValue = <3e1758f6 0f04f670 5c150cd4 55f0a0eb b5c1a17e 8b1abdcc ab7044ba fd02dd5e>;
Client = <c52499f9 a0f482f7 9bdcb115 8217e157 1861f63a e926b55c e7cc85bb b4044464>;
DataValue = <43afe89a 90c53a31 4b839b5f b914896b 8ad165de dd46a159 6aac5f86 2d75058c>;
DataValueCollection = <78dce1b0 9f20a1a9 15004f99 65d71d00 46e7c949 80d599ea 622b2574 be9245a4>;
DateValue = <54571596 1267b4f2 5f14ee12 a0be1b3f 53d79056 7d612f33 e827b90e 7c4c847b>;
DirectoryItem = <b716a315 e40d91b6 18bb918e ab448086 48bc62b2 5a26e959 2c4a0cb4 8fc8d319>;
DirectoryNode = <c718b896 a2a90890 596409a2 c50240aa 1e5e347c f9d9c4df 1a5567fe 8bca7ed3>;
DoubleValue = <b63cba59 de2b200e 199c5ec4 ce17494a a8df75be bac353c0 3c5d9af7 fbf36240>;
Group = <0e912576 760d5fd4 df8a5bbe 13b7922d 6760a046 ea6fee68 3fcd4bd4 c9de7b3b>;
Inspection = <e7fc6688 bee2906d 8f8b7f5e 4f69d1da 59bdbb17 0a620529 c0abc426 d164a44f>;
InspectionMetaData = <982fe134 141245a4 97ca1cde aaa04843 90746c85 80ddedcc ed63b9a4 b3d40477>;
IntegerValue = <97fbd40d a463d4ed 282aa03b 4b5892fe 7fcac137 b4cc590b 03d79bb9 cfee4517>;
Observation = <651371ad be372494 10e31b83 509db973 6021af3b 79895e59 f38e0a9f 0b35a63e>;
ObservationGroup = <92f680bb b4b5243c 83b665e6 35e0d569 634aa24f 455de69e c8c3b666 84c6a858>;
Project = <97879f96 cdc99c88 6e6a614f aa81519b 2ba1f415 e4424a57 66d3f32e 3700829f>;
ProjectPreferredTemplate = <35381035 33dac226 aaeee194 fcd8ad4c e5c5506f a2c597ce 24ba7256 6f34f084>;
SchemaDataRepresentation = <c1843de9 2192b6f8 8f68d807 d5b0d2ac ab276b3c 67c48dc4 f363d92d 89ce1019>;
StringValue = <a7948007 c3454244 7cea0dcd c85b69b5 db5501fb 35e2a242 31907b97 558f1fb0>;
TemplateMetaData = <8f0702e9 8bbb5d4f 71c6a455 2a344af6 e967b2bb abcf05d3 96cd9ffc 328fe362>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "4512A0DB-E887-4294-9E75-840B9861ECA8";
"_NSAutoVacuumLevel" = 2;
};
reason = "Can't find model for source store";
}
您应该可以通过核心数据迁移来解决这个问题:http://www.raywenderlich.com/27657/how-to-perform-a-lightweight-core-data-migration
您在尝试重新创建丢失的版本时遇到的错误几乎可以肯定是因为您没有以完全相同的方式重新创建它。如果您不确定,最简单的方法就是再试一次。如果您创建的新文件与旧文件 完全 匹配,那么它没有理由不工作。
如果您不能这样做,您可以使用以下方法从应用程序的应用商店副本恢复模型:
如果您从 Xcode 存档(.xcarchive
)开始,那只是一个包含应用程序包和一些其他内容的文件包。浏览它以找到包含 all 核心数据模型的 momd
,然后查看该包内部以找到与您缺少的版本匹配的单个 mom
。将该文件复制到存档之外的某个位置。
如果您从 ipa
开始,那只是一个包含该应用程序的 zip 文件。用任何你喜欢的解压工具解压它,然后按照上面的步骤找到正确的 mom
.
mom
文件是编译后的模型,但与源码不同的是,模型编译是可以逆向的。在 Xcode 中创建一个新的模型版本并删除其中的 所有内容 以便它完全为空。然后转到编辑器菜单和select导入...。导入您在上面找到的 mom
文件。
您现在应该拥有一个与您的应用中的编译模型完全对应的 Core Data 模型版本。 将它提交到您的源代码存储库,以便下次使用。