核心数据无法自动轻量迁移

时间:2016-11-20 23:43:15

标签: core-data xcode8 core-data-migration xcdatamodel nspersistentstore

每次Core Data尝试在我的应用程序中创建新版本的模型(我们称之为“Model 2.6”)后尝试进行自动轻量级迁移时崩溃(目前使用“Model 2.5”)。

我一直在使用Core Data一段时间了,而且我很清楚,每当我需要为新版本更改模型时,我必须使用“编辑器 - >添加模型版本”,给出该版本是新标识符,并使用“当前版本”弹出窗口切换到该标识符。我熟悉“用于打开商店的模型与用于创建商店的模型不兼容”错误,因为我之前犯过这个错误。我相信我遇到了一个不同的问题,虽然得到了同样的错误信息。

在周末的大部分时间里,我对此表示反对之后,我希望之前有人看过这个,并提供一些圣人建议。

以下是触发此问题的步骤:

  1. 重置模拟器,核心派生数据,清理构建并保存文件 2.5格式。
  2. 在Xcode中,编辑 - >添加模型版本......
  3. 使用该向导根据“Model 2.5”制作“Model 2.6”
  4. 将新家伙的标识更改为“2.6”
  5. 对自动轻量级迁移完全兼容的新版本执行一些非常简单的操作,例如添加新实体。
  6. 在当前版本
  7. 的弹出窗口下设置“Model 2.6”
  8. 重建&在模拟器中启动。打开我刚刚保存的2.5文件时崩溃。
  9. 我已经成功管理了9个不同版本的文件格式更新,自动轻量级迁移始终完美无缺,直到现在。

    现在和上次之间的差异:

    • 我的模型的2.5版本是我第一次将“工具版本”设置为“自动(Xcode 8)”。所有先前版本都设置为“Xcode 7.3”,因此这将是第一次从已经在“自动(Xcode 8)”上的模型版本进行迁移
    • 我的xcdatamodeld(以及因此的momd文件)现在存在于我的共享框架而不是主机应用程序中(因此我可以在扩展,tvOS等之间共享代码/资源),尽管我尝试撤消此更改以查看它是否是原因,但错误仍然存​​在。
    • 老实说,我不确定。这本来应该是一项微不足道的长达一小时的任务,而且它已经变成了两天的搔痒。

    这是调用

    后记录的实际错误
    [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:self.mainURL options:storeOptions error:&error]
    

    其中storeOptions为{NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1;由于某种原因,有两个:一个用于文件.Model.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3,另一个用于文件Model.sqlite,可能是迁移过程的一部分。 (代码= 134 110 ,基础代码= 134 100

    2016-11-20 16:49:26.928867 Lightbow[27831:356321] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/pwr/Library/Developer/CoreSimulator/Devices/8BDBBB41-ECF6-4646-BA13-DFFD02C40A62/data/Containers/Data/Application/8AE75536-DB51-453F-AEC2-6531F6A0675A/Library/Application%20Support/Lightbow/.Model.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3 options:{
        NSSQLitePragmasOption =     {
            "journal_mode" = "<null>";
        };
    } ... returned error Error Domain=NSCocoaErrorDomain Code=134100 "(null)" UserInfo={metadata={
        NSPersistenceFrameworkVersion = 752;
        NSStoreModelVersionHashes =     {
            LBAlarmTrigger = <a84c55da 7fabee63 d6f9965b 4a8408bb aaabc674 bdaff438 347e1ed4 44adb186>;
            LBAliasTarget = <d1cdfcbc 1fecf252 1e5ef2e4 6faa5735 6e990645 b8a8a1a6 5db79d93 622ef7af>;
            LBAppEventTrigger = <99063c81 4ffe9fec b4092be9 bda6b5cb a1cd8745 400a8a2c 6b44c3e5 abfba541>;
            LBAssignment = <bf29b799 abdb6883 0831f861 bb255cf1 5300e503 971ba129 81a18a61 2955eb18>;
            LBAudioReference = <0c155311 c41aff4f ebcbea65 1a6ee54a 39039c9a fdcc78e0 d5c21295 38a9069d>;
            LBBundledAudioReference = <4c3a5f7b d475af0e df276979 c8ede1cb 24fd616f 7ef33a71 b7302d68 65246848>;
            LBCTLightState = <a5c2a06e 72caae63 0b8af8c3 d1be96f0 177ae06e c15120d4 a360b8a0 219c5911>;
            LBCollection = <f8c72dfe 0c446e24 0913fcfb f2e603bf 0b3a2d2d 742cda3d 0888d734 2fec4e42>;
            LBCollectionItem = <e0a4fd81 4225db2c 5cb0c08d 643324bd 7b23d53a d98deb16 5fa23bf0 a8cdc512>;
            LBFadeThroughTransition = <6a37014b c8064ad1 69422f5b d31fa09c 5d61fc01 2b5a50f7 2aadd2e6 76430357>;
            LBGroup = <cee84942 402b44d9 905ddb29 84b5f86d d2514f21 e91d9e85 c56c1bd5 de32f3a8>;
            LBHSBLightState = <c9926442 5ee27261 c633555a c6259ad9 616b0e23 f5593f5d c82b9f5b 377ff428>;
            LBHardwareEventTrigger = <07bd5b0e f52d4701 719c29bc 3a0eed4b b6a93a6d ff596a7d 9b9f98c0 39a805ce>;
            LBLight = <4cdd2589 13b20fe0 cc2fa2c6 ce23f092 d45e0bfd 2e5f1421 1be6e0ab a051b6d5>;
            LBLightMaster = <95b22dc3 e73a2388 26768e66 1059d41d 40121a30 a3df95da d94649b4 2ed501e8>;
            LBLightState = <5e36f926 259d7ef2 8212622c 821182b2 44ade18f 5e8d4fe5 e715f09e 4dc7156f>;
            LBMediaItemReference = <28b87019 ffd085e6 944c4a0c fc822b47 68975cff a0ca1484 16888ccf ca89b407>;
            LBPreset = <30fa1d52 bac80149 6fee4319 94e16614 cd0830d3 c6414bf6 d48831dc 4a4495b5>;
            LBResourceIdentifier = <dedc1079 739eac97 fbc42105 4a64a53e a3ae6c17 00a48ae2 29d30369 e36a3d11>;
            LBTimerTrigger = <66736edf 9f104506 e1950ac1 b57062c8 eda65031 d01392ae 51ad7d70 b3143468>;
            LBTiming = <362157d7 155e430b 63149c49 5fa84a5f a26a85ee 61ed5748 2f125948 7d4bfeb0>;
            LBTransition = <00c8f3a1 fd66426a d0778e83 f51fe772 ab15e7e8 981f2819 aaf10bfc 15384b22>;
            LBTrigger = <42c5754c 424e6c9c fc0cf034 e40a4d9c 8fa33236 f9116baa 6c79c248 c6de45d2>;
            LBXYLightState = <893ae1a2 4566602f 214572fe aa0eb10f a50e1b1f 2cb5bfff 764892ff 86a62a5b>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =     (
            "2.5"
        );
        NSStoreType = SQLite;
        NSStoreUUID = "AD94F9C0-947C-4062-A026-253C6DA20AB6";
        "_NSAutoVacuumLevel" = 2;
    }, reason=The model used to open the store is incompatible with the one used to create the store} with userInfo dictionary {
        metadata =     {
            NSPersistenceFrameworkVersion = 752;
            NSStoreModelVersionHashes =         {
                LBAlarmTrigger = <a84c55da 7fabee63 d6f9965b 4a8408bb aaabc674 bdaff438 347e1ed4 44adb186>;
                LBAliasTarget = <d1cdfcbc 1fecf252 1e5ef2e4 6faa5735 6e990645 b8a8a1a6 5db79d93 622ef7af>;
                LBAppEventTrigger = <99063c81 4ffe9fec b4092be9 bda6b5cb a1cd8745 400a8a2c 6b44c3e5 abfba541>;
                LBAssignment = <bf29b799 abdb6883 0831f861 bb255cf1 5300e503 971ba129 81a18a61 2955eb18>;
                LBAudioReference = <0c155311 c41aff4f ebcbea65 1a6ee54a 39039c9a fdcc78e0 d5c21295 38a9069d>;
                LBBundledAudioReference = <4c3a5f7b d475af0e df276979 c8ede1cb 24fd616f 7ef33a71 b7302d68 65246848>;
                LBCTLightState = <a5c2a06e 72caae63 0b8af8c3 d1be96f0 177ae06e c15120d4 a360b8a0 219c5911>;
                LBCollection = <f8c72dfe 0c446e24 0913fcfb f2e603bf 0b3a2d2d 742cda3d 0888d734 2fec4e42>;
                LBCollectionItem = <e0a4fd81 4225db2c 5cb0c08d 643324bd 7b23d53a d98deb16 5fa23bf0 a8cdc512>;
                LBFadeThroughTransition = <6a37014b c8064ad1 69422f5b d31fa09c 5d61fc01 2b5a50f7 2aadd2e6 76430357>;
                LBGroup = <cee84942 402b44d9 905ddb29 84b5f86d d2514f21 e91d9e85 c56c1bd5 de32f3a8>;
                LBHSBLightState = <c9926442 5ee27261 c633555a c6259ad9 616b0e23 f5593f5d c82b9f5b 377ff428>;
                LBHardwareEventTrigger = <07bd5b0e f52d4701 719c29bc 3a0eed4b b6a93a6d ff596a7d 9b9f98c0 39a805ce>;
                LBLight = <4cdd2589 13b20fe0 cc2fa2c6 ce23f092 d45e0bfd 2e5f1421 1be6e0ab a051b6d5>;
                LBLightMaster = <95b22dc3 e73a2388 26768e66 1059d41d 40121a30 a3df95da d94649b4 2ed501e8>;
                LBLightState = <5e36f926 259d7ef2 8212622c 821182b2 44ade18f 5e8d4fe5 e715f09e 4dc7156f>;
                LBMediaItemReference = <28b87019 ffd085e6 944c4a0c fc822b47 68975cff a0ca1484 16888ccf ca89b407>;
                LBPreset = <30fa1d52 bac80149 6fee4319 94e16614 cd0830d3 c6414bf6 d48831dc 4a4495b5>;
                LBResourceIdentifier = <dedc1079 739eac97 fbc42105 4a64a53e a3ae6c17 00a48ae2 29d30369 e36a3d11>;
                LBTimerTrigger = <66736edf 9f104506 e1950ac1 b57062c8 eda65031 d01392ae 51ad7d70 b3143468>;
                LBTiming = <362157d7 155e430b 63149c49 5fa84a5f a26a85ee 61ed5748 2f125948 7d4bfeb0>;
                LBTransition = <00c8f3a1 fd66426a d0778e83 f51fe772 ab15e7e8 981f2819 aaf10bfc 15384b22>;
                LBTrigger = <42c5754c 424e6c9c fc0cf034 e40a4d9c 8fa33236 f9116baa 6c79c248 c6de45d2>;
                LBXYLightState = <893ae1a2 4566602f 214572fe aa0eb10f a50e1b1f 2cb5bfff 764892ff 86a62a5b>;
            };
            NSStoreModelVersionHashesVersion = 3;
            NSStoreModelVersionIdentifiers =         (
                "2.5"
            );
            NSStoreType = SQLite;
            NSStoreUUID = "AD94F9C0-947C-4062-A026-253C6DA20AB6";
            "_NSAutoVacuumLevel" = 2;
        };
        reason = "The model used to open the store is incompatible with the one used to create the store";
    }
    2016-11-20 16:49:27.027401 Lightbow[27831:356321] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/pwr/Library/Developer/CoreSimulator/Devices/8BDBBB41-ECF6-4646-BA13-DFFD02C40A62/data/Containers/Data/Application/8AE75536-DB51-453F-AEC2-6531F6A0675A/Library/Application%20Support/Lightbow/Model.sqlite options:{
        NSInferMappingModelAutomaticallyOption = 1;
        NSMigratePersistentStoresAutomaticallyOption = 1;
    } ... returned error Error Domain=NSCocoaErrorDomain Code=134110 "(null)" UserInfo={NSUnderlyingError=0x6000002564a0 {Error Domain=NSCocoaErrorDomain Code=134100 "(null)" UserInfo={metadata={
        NSPersistenceFrameworkVersion = 752;
        NSStoreModelVersionHashes =     {
            LBAlarmTrigger = <a84c55da 7fabee63 d6f9965b 4a8408bb aaabc674 bdaff438 347e1ed4 44adb186>;
            LBAliasTarget = <d1cdfcbc 1fecf252 1e5ef2e4 6faa5735 6e990645 b8a8a1a6 5db79d93 622ef7af>;
            LBAppEventTrigger = <99063c81 4ffe9fec b4092be9 bda6b5cb a1cd8745 400a8a2c 6b44c3e5 abfba541>;
            LBAssignment = <bf29b799 abdb6883 0831f861 bb255cf1 5300e503 971ba129 81a18a61 2955eb18>;
            LBAudioReference = <0c155311 c41aff4f ebcbea65 1a6ee54a 39039c9a fdcc78e0 d5c21295 38a9069d>;
            LBBundledAudioReference = <4c3a5f7b d475af0e df276979 c8ede1cb 24fd616f 7ef33a71 b7302d68 65246848>;
            LBCTLightState = <a5c2a06e 72caae63 0b8af8c3 d1be96f0 177ae06e c15120d4 a360b8a0 219c5911>;
            LBCollection = <f8c72dfe 0c446e24 0913fcfb f2e603bf 0b3a2d2d 742cda3d 0888d734 2fec4e42>;
            LBCollectionItem = <e0a4fd81 4225db2c 5cb0c08d 643324bd 7b23d53a d98deb16 5fa23bf0 a8cdc512>;
            LBFadeThroughTransition = <6a37014b c8064ad1 69422f5b d31fa09c 5d61fc01 2b5a50f7 2aadd2e6 76430357>;
            LBGroup = <cee84942 402b44d9 905ddb29 84b5f86d d2514f21 e91d9e85 c56c1bd5 de32f3a8>;
            LBHSBLightState = <c9926442 5ee27261 c633555a c6259ad9 616b0e23 f5593f5d c82b9f5b 377ff428>;
            LBHardwareEventTrigger = <07bd5b0e f52d4701 719c29bc 3a0eed4b b6a93a6d ff596a7d 9b9f98c0 39a805ce>;
            LBLight = <4cdd2589 13b20fe0 cc2fa2c6 ce23f092 d45e0bfd 2e5f1421 1be6e0ab a051b6d5>;
            LBLightMaster = <95b22dc3 e73a2388 26768e66 1059d41d 40121a30 a3df95da d94649b4 2ed501e8>;
            LBLightState = <5e36f926 259d7ef2 8212622c 821182b2 44ade18f 5e8d4fe5 e715f09e 4dc7156f>;
            LBMediaItemReference = <28b87019 ffd085e6 944c4a0c fc822b47 68975cff a0ca1484 16888ccf ca89b407>;
            LBPreset = <30fa1d52 bac80149 6fee4319 94e16614 cd0830d3 c6414bf6 d48831dc 4a4495b5>;
            LBResourceIdentifier = <dedc1079 739eac97 fbc42105 4a64a53e a3ae6c17 00a48ae2 29d30369 e36a3d11>;
            LBTimerTrigger = <66736edf 9f104506 e1950ac1 b57062c8 eda65031 d01392ae 51ad7d70 b3143468>;
            LBTiming = <362157d7 155e430b 63149c49 5fa84a5f a26a85ee 61ed5748 2f125948 7d4bfeb0>;
            LBTransition = <00c8f3a1 fd66426a d0778e83 f51fe772 ab15e7e8 981f2819 aaf10bfc 15384b22>;
            LBTrigger = <42c5754c 424e6c9c fc0cf034 e40a4d9c 8fa33236 f9116baa 6c79c248 c6de45d2>;
            LBXYLightState = <893ae1a2 4566602f 214572fe aa0eb10f a50e1b1f 2cb5bfff 764892ff 86a62a5b>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =     (
            "2.5"
        );
        NSStoreType = SQLite;
        NSStoreUUID = "AD94F9C0-947C-4062-A026-253C6DA20AB6";
        "_NSAutoVacuumLevel" = 2;
    }, reason=The model used to open the store is incompatible with the one used to create the store}}, reason=Failed to open the store} with userInfo dictionary {
        NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134100 \"(null)\" UserInfo={metadata={\n    NSPersistenceFrameworkVersion = 752;\n    NSStoreModelVersionHashes =     {\n        LBAlarmTrigger = <a84c55da 7fabee63 d6f9965b 4a8408bb aaabc674 bdaff438 347e1ed4 44adb186>;\n        LBAliasTarget = <d1cdfcbc 1fecf252 1e5ef2e4 6faa5735 6e990645 b8a8a1a6 5db79d93 622ef7af>;\n        LBAppEventTrigger = <99063c81 4ffe9fec b4092be9 bda6b5cb a1cd8745 400a8a2c 6b44c3e5 abfba541>;\n        LBAssignment = <bf29b799 abdb6883 0831f861 bb255cf1 5300e503 971ba129 81a18a61 2955eb18>;\n        LBAudioReference = <0c155311 c41aff4f ebcbea65 1a6ee54a 39039c9a fdcc78e0 d5c21295 38a9069d>;\n        LBBundledAudioReference = <4c3a5f7b d475af0e df276979 c8ede1cb 24fd616f 7ef33a71 b7302d68 65246848>;\n        LBCTLightState = <a5c2a06e 72caae63 0b8af8c3 d1be96f0 177ae06e c15120d4 a360b8a0 219c5911>;\n        LBCollection = <f8c72dfe 0c446e24 0913fcfb f2e603bf 0b3a2d2d 742cda3d 0888d734 2fec4e42>;\n        LBCollectionItem = <e0a4fd81 4225db2c 5cb0c08d 643324bd 7b23d53a d98deb16 5fa23bf0 a8cdc512>;\n        LBFadeThroughTransition = <6a37014b c8064ad1 69422f5b d31fa09c 5d61fc01 2b5a50f7 2aadd2e6 76430357>;\n        LBGroup = <cee84942 402b44d9 905ddb29 84b5f86d d2514f21 e91d9e85 c56c1bd5 de32f3a8>;\n        LBHSBLightState = <c9926442 5ee27261 c633555a c6259ad9 616b0e23 f5593f5d c82b9f5b 377ff428>;\n        LBHardwareEventTrigger = <07bd5b0e f52d4701 719c29bc 3a0eed4b b6a93a6d ff596a7d 9b9f98c0 39a805ce>;\n        LBLight = <4cdd2589 13b20fe0 cc2fa2c6 ce23f092 d45e0bfd 2e5f1421 1be6e0ab a051b6d5>;\n        LBLightMaster = <95b22dc3 e73a2388 26768e66 1059d41d 40121a30 a3df95da d94649b4 2ed501e8>;\n        LBLightState = <5e36f926 259d7ef2 8212622c 821182b2 44ade18f 5e8d4fe5 e715f09e 4dc7156f>;\n        LBMediaItemReference = <28b87019 ffd085e6 944c4a0c fc822b47 68975cff a0ca1484 16888ccf ca89b407>;\n        LBPreset = <30fa1d52 bac80149 6fee4319 94e16614 cd0830d3 c6414bf6 d48831dc 4a4495b5>;\n        LBResourceIdentifier = <dedc1079 739eac97 fbc42105 4a64a53e a3ae6c17 00a48ae2 29d30369 e36a3d11>;\n        LBTimerTrigger = <66736edf 9f104506 e1950ac1 b57062c8 eda65031 d01392ae 51ad7d70 b3143468>;\n        LBTiming = <362157d7 155e430b 63149c49 5fa84a5f a26a85ee 61ed5748 2f125948 7d4bfeb0>;\n        LBTransition = <00c8f3a1 fd66426a d0778e83 f51fe772 ab15e7e8 981f2819 aaf10bfc 15384b22>;\n        LBTrigger = <42c5754c 424e6c9c fc0cf034 e40a4d9c 8fa33236 f9116baa 6c79c248 c6de45d2>;\n        LBXYLightState = <893ae1a2 4566602f 214572fe aa0eb10f a50e1b1f 2cb5bfff 764892ff 86a62a5b>;\n    };\n    NSStoreModelVersionHashesVersion = 3;\n    NSStoreModelVersionIdentifiers =     (\n        \"2.5\"\n    );\n    NSStoreType = SQLite;\n    NSStoreUUID = \"AD94F9C0-947C-4062-A026-253C6DA20AB6\";\n    \"_NSAutoVacuumLevel\" = 2;\n}, reason=The model used to open the store is incompatible with the one used to create the store}";
        reason = "Failed to open the store";
    }
    

    在创建这个新版本时,我是否遗漏了一些明显的东西?要清除的其他任何缓存或隐藏文件?我注意到在创建一个新的Whatever.xcdatamodel时,Xcode中的“Discard All Changes ...”将该文件留下,所以我要特别小心删除测试运行并检查Xcode外的“git status”。

    我对错误消息持怀疑态度,因为我可以将xcdatamodeld的“当前版本”切换回2.5,看到文件打开就好了,将“当前版本”切换为2.6,看到它失败,然后来回走动可预测的成功/失败。它显然能够打开2.5个文档,不知道它何时尝试将它们迁移到2.6。

0 个答案:

没有答案