神奇的记录迁移失败"无法找到源存储的模型"

时间:2014-09-05 10:05:28

标签: core-data magicalrecord

我们对CoreData模型进行了一些更改,看起来自动迁移失败了。

即使我们将当前模型设置为我们用于生成数据的原始模型,仍然存在错误:

reason =“找不到源存储的模型”;

2014-09-05 02:19:43.297[948:166846] -[LBAppDelegate application:willFinishLaunchingWithOptions:] line 132 $ WILL FINISH!!
2014-09-05 02:19:43.402[948:166846] +[LBParse ensureUserObjectExists] line 107 $ dont save
2014-09-05 02:19:52.395[948:166846] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/0B3D4097-940C-433F-B6E5-E0EA6B08992F/Library/Applicat... options:{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
    NSSQLitePragmasOption =    {
        "journal_mode" = WAL;
    };
} ... returned error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x180f8620 {URL=file:///var/mobile/Containers/Data/Application/0B3D4097-940C-433F-B6E5-E0EA6B08992F/Library/Applicat..., metadata={
    NSPersistenceFrameworkVersion = 519;
    NSStoreModelVersionHashes =    {
        AccessItem = <c81a9dbd 17033d2e 91d33b1c fc94ab08 bd3619e2 b5fea24d 6881959a f8023dc5>;
        AccessRule = <e0fd9950 87366a29 fa6702bf 7e7acc3a 86c2f088 3875c341 81414177 4720eee8>;
        Airline = <f8491ecb 2628a003 143b935b 3d3c291b fac507d8 2339af1b 1ac0fe8b 04b73602>;
        Airport = <09e93c0e fbf1e542 d1428584 30549a84 2e0cb9d3 8b50a508 31807dec d7e5f845>;
        Alliance = <b9b53f23 d5962f3f b7a0a3a5 5ca84d83 61d81f7c 0787ca6a dfdfdf21 733b5e4d>;
        AllianceTier = <6ec8bee0 5d4c62f8 1411eaab b464d783 c6388b12 06506824 f11d6453 a58e509a>;
        Amenity = <86065297 64aff55b b7bfec32 e8e14b74 5d7afa5b 751e760e e37e6294 2e40e26a>;
        Data = <92870bec c4a8794e 293dcbe9 93282d69 cb675039 cb9b9bf6 8dda6359 34697663>;
        Event = <de060947 8ec9f2bb 80e341eb 787e7eec 7cc2a09f 356e511c 7d515ca5 130690fe>;
        FeedItem = <1d0d12fc 82eb532a c1a42ad3 57022129 2c44360e ab5514ce a44d6de0 719ca798>;
        Image = <94e1ad81 4a2aa37b 6a02a52e fb481891 5028fafc 0645de55 7316e5d9 f630ca85>;
        Lounge = <57e5d036 c67f1f9d b3c731a6 4136866e 008684b0 f2ec0620 58e6e56c dbbed4fe>;
        ParseObject = <bfa49e8c 1108961a 49848584 0f2fe83f 082bdc6a 2948e09f 68a84c50 2acb0699>;
        Review = <b423b85c 47d15ee8 bbacbfcf 019fb741 165da2ab 5fa6f087 1975bb31 712bdb64>;
        User = <8451767f db80e10a 15ea83d8 83dc1a2c e89d1699 0b302640 59a23144 61c65be0>;
        Vote = <38d267c9 0c44854e dd01201c b728b906 21fd25cd 8343a416 adf769c6 faef7cb6>;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =    (
        ""
    );
    NSStoreType = SQLite;
    NSStoreUUID = "222748EF-2F19-4B87-829C-F8171E439430";
    "_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store} with userInfo dictionary {
    URL = "file:///var/mobile/Containers/Data/Application/0B3D4097-940C-433F-B6E5-E0EA6B08992F/Library/Applicat...";
    metadata =    {
        NSPersistenceFrameworkVersion = 519;
        NSStoreModelVersionHashes =        {
            AccessItem = <c81a9dbd 17033d2e 91d33b1c fc94ab08 bd3619e2 b5fea24d 6881959a f8023dc5>;
            AccessRule = <e0fd9950 87366a29 fa6702bf 7e7acc3a 86c2f088 3875c341 81414177 4720eee8>;
            Airline = <f8491ecb 2628a003 143b935b 3d3c291b fac507d8 2339af1b 1ac0fe8b 04b73602>;
            Airport = <09e93c0e fbf1e542 d1428584 30549a84 2e0cb9d3 8b50a508 31807dec d7e5f845>;
            Alliance = <b9b53f23 d5962f3f b7a0a3a5 5ca84d83 61d81f7c 0787ca6a dfdfdf21 733b5e4d>;
            AllianceTier = <6ec8bee0 5d4c62f8 1411eaab b464d783 c6388b12 06506824 f11d6453 a58e509a>;
            Amenity = <86065297 64aff55b b7bfec32 e8e14b74 5d7afa5b 751e760e e37e6294 2e40e26a>;
            Data = <92870bec c4a8794e 293dcbe9 93282d69 cb675039 cb9b9bf6 8dda6359 34697663>;
            Event = <de060947 8ec9f2bb 80e341eb 787e7eec 7cc2a09f 356e511c 7d515ca5 130690fe>;
            FeedItem = <1d0d12fc 82eb532a c1a42ad3 57022129 2c44360e ab5514ce a44d6de0 719ca798>;
            Image = <94e1ad81 4a2aa37b 6a02a52e fb481891 5028fafc 0645de55 7316e5d9 f630ca85>;
            Lounge = <57e5d036 c67f1f9d b3c731a6 4136866e 008684b0 f2ec0620 58e6e56c dbbed4fe>;
            ParseObject = <bfa49e8c 1108961a 49848584 0f2fe83f 082bdc6a 2948e09f 68a84c50 2acb0699>;
            Review = <b423b85c 47d15ee8 bbacbfcf 019fb741 165da2ab 5fa6f087 1975bb31 712bdb64>;
            User = <8451767f db80e10a 15ea83d8 83dc1a2c e89d1699 0b302640 59a23144 61c65be0>;
            Vote = <38d267c9 0c44854e dd01201c b728b906 21fd25cd 8343a416 adf769c6 faef7cb6>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =        (
            ""
        );
        NSStoreType = SQLite;
        NSStoreUUID = "222748EF-2F19-4B87-829C-F8171E439430";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "Can't find model for source store";
}
2014-09-05 02:19:52.404 [948:166846] CoreData: annotation: NSPersistentStoreCoordinator's current model hashes are {
    AccessItem = <c81a9dbd 17033d2e 91d33b1c fc94ab08 bd3619e2 b5fea24d 6881959a f8023dc5>;
    AccessRule = <e0fd9950 87366a29 fa6702bf 7e7acc3a 86c2f088 3875c341 81414177 4720eee8>;
    Airline = <f8491ecb 2628a003 143b935b 3d3c291b fac507d8 2339af1b 1ac0fe8b 04b73602>;
    Airport = <09e93c0e fbf1e542 d1428584 30549a84 2e0cb9d3 8b50a508 31807dec d7e5f845>;
    Alliance = <b9b53f23 d5962f3f b7a0a3a5 5ca84d83 61d81f7c 0787ca6a dfdfdf21 733b5e4d>;
    AllianceTier = <6ec8bee0 5d4c62f8 1411eaab b464d783 c6388b12 06506824 f11d6453 a58e509a>;
    Amenity = <86065297 64aff55b b7bfec32 e8e14b74 5d7afa5b 751e760e e37e6294 2e40e26a>;
    FeedItem = <1d0d12fc 82eb532a c1a42ad3 57022129 2c44360e ab5514ce a44d6de0 719ca798>;
    Image = <94e1ad81 4a2aa37b 6a02a52e fb481891 5028fafc 0645de55 7316e5d9 f630ca85>;
    Lounge = <57e5d036 c67f1f9d b3c731a6 4136866e 008684b0 f2ec0620 58e6e56c dbbed4fe>;
    ParseObject = <bfa49e8c 1108961a 49848584 0f2fe83f 082bdc6a 2948e09f 68a84c50 2acb0699>;
    Review = <b423b85c 47d15ee8 bbacbfcf 019fb741 165da2ab 5fa6f087 1975bb31 712bdb64>;
    User = <8451767f db80e10a 15ea83d8 83dc1a2c e89d1699 0b302640 59a23144 61c65be0>;
    Vote = <38d267c9 0c44854e dd01201c b728b906 21fd25cd 8343a416 adf769c6 faef7cb6>;
}

2 个答案:

答案 0 :(得分:9)

你有一个型号,但它与商店不兼容。在我看来,你在没有添加版本的情况下对模型进行了更改。使用任何Core Data迁移,您都需要源模型和目标模型。也就是说,Core Data需要知道原始数据的样子,以及新数据的样子。然后,核心数据可以推断(推断)自动迁移模型之间的变化。由于在这种情况下找不到源模型,并且我假设您仍然有项目中的模型,因此您可能在不添加版本的情况下更改了数据模型。希望您使用的是某些源代码控制,并且可以恢复到与商店匹配的dat模型版本。从那里,您需要“添加模型版本”。在其中一个Xcode菜单中查找它。您还需要确保新版本是当前模型版本,以便正确启动迁移。

而且,如果你正在使用MagicalRecord,你可以使用一种简单的辅助方法,在附加商店时迁移数据。

答案 1 :(得分:5)

如果您的先前版本未更改,但您有多个xcdatamodel文件,并且正在使用mergedModelFromBundles:加载它们,也会发生这种情况。这就是MagicalRecord加载模型文件的方式。

因此,如果您具有另一个xcdatamodel的依赖性(可能来自您的pod),那么您的实际source data model将与您要迁移的实际mergedModelFromBundles:不同,因为源数据模型表示合并的模型因source data model而导致的一切。

要解决此问题,您需要创建一个与存储的内容匹配的前一版本,而不仅仅是您之前版本中的内容。为此,请将缺少的模型添加到要迁移的xcdatamodel,并从其他Main.xcdatamodel Version 2: Users, Posts, Comments Version 1: Users, Posts Other.xcdatamodel Version 1: Events, Data 获取这些模型。幸运的是,您可以通过在实体列表中选择它们来复制和粘贴整个模型。

例如:

之前:(失败)

Main.xcdatamodel 
  Version 2: Users, Posts, Comments
  Version 1: Users, Posts, Events, Data
Other.xcdatamodel
  Version 1: Events, Data

之后:

Version 1: Users, Posts, Events, Data
Version 2: Users, Posts, Comments, Events, Data

存储数据模型:

{{1}}