Magical record migration failing "Can't find model for source store"
Asked Answered
G

2

5

We made some changes to our CoreData model and looks like the auto migration is failing.

Even when we set the current model to be the original model that we used to generate the data there's still the error:

reason = "Can't find model for source store";

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>;
}
Grounder answered 5/9, 2014 at 10:5 Comment(2)
Can you post a little of your setup code? How are you turning on core data and initiating migrations?Tonsillotomy
I had the same error. But it was my fault. Finally it turned out that I had changed the old model unintentional.Banal
T
9

You have a model, but it's not compatible with the store. What it seems to me is that you made a change to the model without adding a version. With any Core Data migration, you need a source model and the destination model. That is, Core Data needs to know what the original data looks like, and what the new data looks like. From there, Core Data can then deduce (infer) the changes between models for automatic migrations. Since the source model isn't found in this case, and I'm assuming you still have a model that is in your project, it's likely you changed the data model without adding a version. Hopefully, you're using some source control and can revert to the version of the dat model that matches the store. From there, you'll need to 'Add Model Version'. Look for it in one of the Xcode menus. You'll also need to make sure the new version is the current model version for the migration to kick off properly.

And, if you're using MagicalRecord, you can use one of the simple helper methods that migrate data when a store is attached.

Tonsillotomy answered 5/9, 2014 at 15:48 Comment(5)
This is so logical, i struggled quite some time.Bellamy
What if we actually did add a version and still get the same issue? The original model wasn't changed.Either
Like Maciej, we're also having an issue with this error cropping up even though the original model is unchanged and the new model only adds one field.Puett
Same issue as Maciej and brainfree. I even compared the hashes and the model is compatible with the store. So I don't know what's wrong.Oldenburg
@MatíasR I had the same issue and it had to do with MagicalRecord and multiple data models, it's a bit of long answer, so I posted it below this one. Good luck!Mineral
M
5

This can also happen when your previous version hasn't changed, but you have multiple xcdatamodel files and are loading them with mergedModelFromBundles:. This is how MagicalRecord loads your model files.

So if you have a dependancy (possibly from your pods) that has another xcdatamodel then your actual source data model will not be the same as the one that you are migrating from as the source data model is representing a merged model of everything due to the mergedModelFromBundles:.

To solve this issue you will need to create a pervious version that matches whats stored, not just whats in your previous version. To do this add the missing models to the source data model that you are migrating from and you get these models from the other xcdatamodel. Luckily you can just copy and paste the whole models by selecting them in the entity listing.

For Example:

Before: (Fails)

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

After:

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

Stored Data Model:

Version 1: Users, Posts, Events, Data
Version 2: Users, Posts, Comments, Events, Data
Mineral answered 14/4, 2015 at 2:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.