如何恢复丢失的 CoreData 模型版本?
Posted
技术标签:
【中文标题】如何恢复丢失的 CoreData 模型版本?【英文标题】:How can I restore a CoreData Model version that has gone missing? 【发布时间】:2015-01-20 04:05:27 【问题描述】:所以,我搞砸了。我在 Xcode 中创建了现有 CoreData 模型的新版本,但不知何故最终没有提交 .xcdatamodel
文件(或更准确地说,是其中的 contents
文件)。现在,过了一会儿,那个文件不见了,我无法恢复它。尝试在 xcode 中打开 xcdatamodel 文件时出现错误“无法打开文件“内容”,因为没有这样的文件”。
我想我可以很聪明,从以前版本的 .xcdatamodel
文件中复制 contents
文件,然后添加回我为此迁移添加的表(幸运的是,我只添加了一个表和生成了一个类,因此再次创建表很容易)。问题是,当我在模拟器或已经存在数据的设备上运行应用程序时,我收到以下错误: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";
【问题讨论】:
您是否有包含此版本模型的编译副本的应用程序的先前版本? 是的,我愿意。它存档在 Xcode 中,加上 TestFlight。有没有办法从中获取模型? 这个答案为我解决了这个问题:***.com/a/33078239/1069884 查看我的回答on this post。它至少对我有用。 :) 【参考方案1】:您在尝试重新创建丢失的版本时遇到的错误几乎可以肯定是因为您没有以完全相同的方式重新创建它。如果您完全不确定,最简单的方法就是再试一次。如果您创建的新版本与旧版本精确匹配,那么它没有理由不工作。
如果您不能这样做,您可以使用以下方法从应用的应用商店副本中恢复模型:
如果您从 Xcode 存档(.xcarchive
)开始,那只是一个包含应用程序包和其他一些东西的文件包。浏览它以找到包含所有核心数据模型的momd
,然后在该包中查找与您丢失的版本匹配的单个mom
。将该文件复制到存档之外的某个位置。
如果您以 ipa
开头,那只是一个包含应用程序的 zip 文件。用你喜欢的任何解压工具解压,然后按照上面的方法找到正确的mom
。
mom
文件是编译后的模型,但与源代码不同,模型编译可以反转。在 Xcode 中创建一个新的模型版本并删除其中的所有内容,使其完全为空。然后转到编辑器菜单并选择导入...。导入您在上面找到的mom
文件。
您现在应该有一个与您的应用程序中编译的模型完全对应的 Core Data 模型版本。 将其提交到您的源代码存储库,以便下次使用。
【讨论】:
不幸的是,我仍然无法让它工作。我导入了我的 v15mom
文件,但它仍然给我同样的错误。比较错误中的哈希值(现在粘贴在我的问题中)表明其中两个模型是不同的,但我不知道为什么它们会不同;我不记得有一段时间改变它们了。无论如何,我正在使用来自发送到 TestFlight 的二进制文件中的mom
文件...
您得到的错误是“找不到源存储的模型”。这表明您使用的mom
实际上与您当前的持久存储文件不对应。也许你不小心抓错了?或者,当您创建新模型版本时,您可能不小心将其设为最新版本,而实际上并非如此。看看去年的这个答案也可能会有所帮助,我对同一件事的解释略有不同:***.com/questions/21306257/…
因为我怀疑我可能做错了什么,所以我想澄清一些事情。我的xcdatamodeld
中有 15 个xcdatamodel
版本。其中最新的也是当前版本 (v15) 以及缺少 contents
文件的版本。如果我基于 v14 制作新版本(v16),清除内容并导入 v15 mom
文件,由于缺少 contents
文件,我仍然无法构建。如果我从 v14 或 v16 复制该文件,则会收到与上述类似的错误。 (虽然不同的哈希)。我错过了什么?
啊哈!我最终做的是将 v14 contents
文件复制到 v15 xcdatamodel
(不起作用),然后查看哪些哈希不匹配并从新的 v16 复制这些模型到 v15s 的顶部(删除这些表的 v15s 版本)。起初它仍然不起作用,但我不得不通过选择正确的逆关系将 2-way 关系合并为一个,使其再次匹配。事后看来,这可能是我从一开始就缺少的东西。谢谢汤姆。
@TomHarrington。你能帮我***.com/questions/43279438/…【参考方案2】:
您应该能够通过核心数据迁移来解决这个问题:http://www.raywenderlich.com/27657/how-to-perform-a-lightweight-core-data-migration
【讨论】:
你是说重新创建一个新的迁移?我目前使用的是版本 15(缺少文件的版本)。我尝试创建一个基于 v14 的新迁移,并添加了缺少的表等,但它不会构建。所以我尝试将contents
文件(或者从v14 和新的v16)复制到v15,它会构建,但是当它尝试访问数据库时仍然会崩溃。以上是关于如何恢复丢失的 CoreData 模型版本?的主要内容,如果未能解决你的问题,请参考以下文章
完全丢失 /Applications/XAMPP 文件夹 - 我该如何恢复? (XAMPP 和 Mac OSX 10.15.3)