ios - 核心数据迁移错误 Cocoa error 134130 Can't find model for source store

标签 ios objective-c core-data core-data-migration

我的应用已在应用商店上线。我对核心数据模型进行了更新。我关注了 Apple dev 网站上的核心数据轻迁移。

  • 在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 文件。如果我删除我的应用程序并在应用程序商店下载当前版本,从保管箱恢复 3 个文件,转到任何使用核心数据的屏幕,它会崩溃。

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

    最佳答案

    我能够通过检查过去的提交方式来获得正确的旧数据模型并解决问题。谢谢大家

    关于ios - 核心数据迁移错误 Cocoa error 134130 Can't find model for source store,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29290166/

    相关文章:

    iOS:可达性 - 返回应用程序后 startNotifier 失败

    ios - 如何修复 IOS 中 SBJSON 文件中的内存泄漏

    iphone - Three20 是否提供替代 CoreData 框架的简化安装?

    ios - 滚动到 UITextView 文本的末尾

    objective-c - Objective-C - 自定义 View 和实现 init 方法?

    ios - 对核心数据进行排序 nsarray numeric

    iOS 核心数据一对一自反关系谓词

    ios - MBCalendarKit 错误框架

    ios - App结构 : UIView vs. 分页界面中的UIViewController

    objective-c - CVPixelBufferRef 的优化