ios - 如何恢复丢失的 CoreData 模型版本?
<p><p>所以,我搞砸了。我在 Xcode 中创建了现有 CoreData 模型的新版本,但不知何故最终没有提交 <code>.xcdatamodel</code> 文件(或更准确地说,是其中的 <code>contents</code> 文件)。现在,过了一会儿,那个文件不见了,我无法恢复它。尝试在 xcode 中打开 xcdatamodel 文件时出现错误“无法打开文件“内容”,因为没有这样的文件”。</p>
<p>我想我可以很聪明,从以前版本的 <code>.xcdatamodel</code> 文件中复制 <code>contents</code> 文件,然后将我为此迁移添加的表添加回(幸运的是,我只添加了一个表并生成了一个类,因此再次创建表很容易)。问题是,当我在模拟器或已经存在数据的设备上运行应用程序时,我收到以下错误:<code>Error Domain=NSCocoaErrorDomain Code=134130 "The operation could not be completed. (Cocoa error 134130. )"</code></p>
<p>该错误还列出了 NSPersistentStoreCoordinator 的当前模型哈希值,所以现在我假设相关模型的哈希值可能不同。</p>
<p>我在这里有什么选择?如何修复数据,以便用户不必卸载应用程序并在更新前丢失所有数据?</p>
<p>以下是错误的完整内容:</p>
<pre><code>2015-01-21 11:01:11.050 Marq 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 CoreData: annotation: (migration) will attempt automatic schema migration
2015-01-21 11:01:11.335 Marq 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 - 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";
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您在尝试重新创建丢失的版本时遇到的错误几乎可以肯定是因为您没有以完全相同的方式重新创建它。如果您完全不确定,最简单的方法就是再试一次。如果您创建的新版本与旧版本<strong>精确</strong>匹配,那么它没有理由不工作。</p>
<p>如果您不能这样做,您可以使用以下方法从应用的应用商店副本中恢复模型:</p>
<p>如果您从 Xcode 存档(<code>.xcarchive</code>)开始,那只是一个包含应用程序包和其他内容的文件包。浏览它以找到包含 <strong>all</strong> 您的 Core Data 模型的 <code>momd</code>,然后在该包中查找与您丢失的版本匹配的单个 <code>mom</code> .将该文件复制到存档之外的某个位置。</p>
<p>如果您从 <code>ipa</code> 开始,那只是一个包含应用程序的 zip 文件。用你喜欢的解压工具解压,然后按照上面的方法找到合适的<code>mom</code>。</p>
<p><code>mom</code> 文件是编译后的模型,但与源代码不同,模型编译可以反向。在 Xcode 中创建一个新的模型版本并删除其中的<em>所有内容</em>,使其完全为空。然后转到<strong>编辑器</strong>菜单并选择<strong>导入...</strong>。导入上面找到的 <code>mom</code> 文件。</p>
<p>您现在应该有一个与您的应用程序中编译的模型完全对应的 Core Data 模型版本。 <strong>将其提交到您的源代码存储库</strong>,以便下次使用。</p></p>
<p style="font-size: 20px;">关于ios - 如何恢复丢失的 CoreData 模型版本?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/28037593/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/28037593/
</a>
</p>
页:
[1]