【问题标题】:Core Data migration with Magical Record fails with "Removed incompatible model version"使用 Magical Record 迁移核心数据失败并显示“已删除不兼容的模型版本”
【发布时间】:2023-03-27 22:03:01
【问题描述】:

我正在尝试添加我的核心数据模型的新版本。我过去成功地做到了这一点,但这次我根本无法让它迁移。我正在使用 Magical Record 进行 Core Data 处理,场景如下;

  1. 核心数据堆栈在 AppDelegate 中的 application didFinishLaunchingWithOptions 期间设置
  2. 设置方法是:

    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"MyDb.sqlite"];**
    
  3. 我添加了新版本的 .xcdatamodel 并将新版本设置为当前版本。
  4. 应用程序启动时,Magical Record 报告以下问题; “删除了不兼容的模型版本”。

我认为这一定是轻量级迁移规则的问题,但即使我只是添加新版本的 .xcdatamodel 而不对其进行任何更改,它仍然不会迁移。您对正在发生的事情有任何想法吗?现在已经为此苦苦挣扎了几天,似乎无法弄清楚。

【问题讨论】:

    标签: ios objective-c core-data magicalrecord


    【解决方案1】:

    这是我目前使用的(抱歉 Swift 代码),但我使用的是最新版本的 MagicalRecord:

        var dbPath = NSPersistentStore.MR_defaultLocalStoreUrl();
        MagicalRecord.setLoggingLevel(MagicalRecordLoggingLevel.Error);
        MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStoreAtURL(dbPath);
    

    这段代码可以毫无问题地进行简单的迁移。只是为了确保我添加了一些额外的字段并查看了我的数据库的内容。一切都很好。

    我的 MagicalRecord Podfile 条目:

    pod 'MagicalRecord', :git => "https://github.com/magicalpanda/MagicalRecord.git"

    【讨论】:

    • 感谢您的建议。尝试使用 NSUrl 设置堆栈,而不是将名称作为 NSString 传递,但迁移仍然失败。
    猜你喜欢
    • 2012-09-20
    • 1970-01-01
    • 2023-03-14
    • 2013-04-24
    • 2011-09-23
    • 2012-07-20
    • 2011-05-30
    • 1970-01-01
    • 2021-08-11
    相关资源
    最近更新 更多