核心数据迁移错误 Cocoa 错误 134130 找不到源存储的模型



我的应用程序在应用程序商店中运行。我对核心数据模型进行了更新。我在苹果开发网站上关注了核心数据轻迁移。

  • 在Xcode中添加模型的新版本
  • 对新模型版本进行更改
  • 选择选项以使用模型的新版本(新模型版本带有绿色复选框)
  • 将sqlite文件添加到持久存储时添加选项

这是代码:

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];

我一直遇到这个错误,它找不到我的原始(旧版本)模型。奇怪的是,当我在开发过程中测试它时,它成功了。我发布到应用商店,现在它在我所有用户的设备上崩溃了。

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}

我试图恢复到应用商店中上一个稳定发布版本的代码库,但我也遇到了一个核心数据错误"模型与商店不兼容"或类似的错误。

这把我逼疯了。有人能谈谈这个问题吗?

编辑:我的应用程序可以将核心数据文件备份到dropbox。它备份sqlite文件以及-shm和-wal文件。如果我删除我的应用程序并在应用程序商店下载当前版本,从dropbox恢复3个文件,转到任何使用核心数据的屏幕,它都会崩溃。

有没有一种简单的方法可以从sqlite导出数据,并将其导入到新模型的核心数据中?

我能够通过过去的提交方式获得正确的旧数据模型并修复问题。感谢所有

最新更新