imObjCSwifting
imObjCSwifting

Reputation: 743

Core data migration error Cocoa error 134130 Can't find model for source store

My app is live on the app store. I made an update with changes to the core data model. I followed the core data light migration on Apple dev website.

Here is the code:

NSString *momdPath = [[NSBundle mainBundle] pathForResource:@"PropertiesModel" ofType:@"momd"];
    model = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:momdPath]];

//    model = [NSManagedObjectModel mergedModelFromBundles:nil];

    psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];

    NSString *path = [self itemArchivePath];
    NSURL *storeURL = [NSURL fileURLWithPath:path];

    NSError *error = nil;
    NSDictionary *options = @{ NSMigratePersistentStoresAutomaticallyOption : @(YES),
                               NSInferMappingModelAutomaticallyOption : @(YES),
                               NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"}};
    if (![psc addPersistentStoreWithType:NSSQLiteStoreType
                           configuration:nil
                                     URL:storeURL
                                 options:options
                                   error:&error]) {
        CLS_LOG(@"store URL: %@ \n options: %@ \n error: %@",storeURL,options,error);
        [NSException raise:@"Open failed" format:@"Reason: %@, Full Error: %@", [error localizedDescription],error];
    }

    // Create the managed object context
    context = [[NSManagedObjectContext alloc] init];
    [context setPersistentStoreCoordinator:psc];

I keep running into this error that it cannot find my original (old version) model. The weird thing is when I tested it during development, it worked. I released to the app store and now it is crashing on all my user's device.

Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x170671dc0 {URL=file:///var/mobile/Containers/Data/Application/68165624-8866-4722-8472-F371A1202A83/Documents/DIYLandLord.data, metadata={
    NSPersistenceFrameworkVersion = 519;
    NSStoreModelVersionHashes =     {
        Contractor = <6e29455a 13768a19 a9a4a2da 1d8d492e b3cc023d bc06cb0d 298b56e1 b44fba9f>;
        Expense = <847aa2e8 da0a2730 4b0a70a2 2051ed2c 09ece5c4 e1a39c10 a42f0aa2 d5b79ad4>;
        InAppPurchase = <51dc7a31 415ba244 9c175d8f e14f6948 7ebec6a3 463d2995 3ad0b60b 8bd06f7d>;
        Owner = <2eaaaa38 ff6c4d19 6bb2621b 91a2c61a 9f5e564e 4703c68c 880f8ab4 4e1d2408>;
        Payment = <e92d19bd 82637935 88cf8493 e0c73ddc d1ba245e 0d1e49e4 8c6bc876 e9a97372>;
        Property = <456365b5 9f1b3cda 92f663ef 5f8b90a1 4dc5842b 20f58a7c 4521f182 f733e99f>;
        Tenant = <f3a92b85 dace78cb ae9cba8f 73419929 6932ca12 4ff97ebf 8e2d7689 da9c242b>;
        Unit = <922b8c16 930cd7b7 05259da0 79ace226 bd379991 955bfc4a 755a72ef 1e5dac4c>;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =     (
        ""
    );
    NSStoreType = SQLite;
    NSStoreUUID = "27CE8843-4E80-4F4A-A728-559465D687F8";
    "_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store}

I tried to revert back to the code base of the last stable release version in the app store but I also runs into a core data error "the model is not compatible with the store" or something like that.

This is driving me nut. Could someone shed some light on this issue please?

Edit: My app can back up core data files to dropbox. It backs up the sqlite file and -shm and -wal files. If i delete my app and download the current version on the app store, restore the 3 files from dropbox, go to any screen that uses core data, it will crash.

Is there an easy way I can export the data from the sqlite and import it to core data with the new model?

Upvotes: 2

Views: 935

Answers (1)

imObjCSwifting
imObjCSwifting

Reputation: 743

I was able to get the correct old data model by checkout a commit way in the past and fix the issue. Thanks all

Upvotes: 0

Related Questions