【问题标题】:Opening Realm files of format version 5 is not supported by this version of Realm此版本的 Realm 不支持打开格式版本 5 的 Realm 文件
【发布时间】:2021-02-01 21:37:19
【问题描述】:

我找不到读取 Realm 文件的方法。我假设 Realm 是向后兼容的。领域对象/属性/类保持完全相同。我尝试更改架构并尝试自定义迁移,这是不可能的,因为当我尝试从 Realm 读取时,我得到“此版本的 Realm 不支持打开格式版本 5 的 Realm 文件”。我尝试了许多我在其他帖子中读到的技巧,例如强制 readOnly 为 false:

    let version = Realm.Configuration.defaultConfiguration.schemaVersion
    print("schema version \(version)")
    var configuration = Realm.Configuration(readOnly: false, schemaVersion: 1)
    try! Realm(configuration: configuration)   //FAILS Opening Realm files of format version 5 is not supported by this version of Realm
    configuration = Realm.Configuration(readOnly: true)
    let realm = try! Realm(configuration: configuration)

我无法在 App Store 上更新应用程序,因为使用以前版本的人的应用程序会崩溃,我不想删除他们的 Realm 文件并因为他们丢失了所有数据而收到差评。有没有不降级到早期版本领域的选择?

我使用的是 XCode 12.4 和 swift 5。Realm 文件的架构没有改变。该问题应该在 2021 年 9 月 20 日在 Realm v5.4.1 中得到解决。我安装了最新版本的 Realm,但问题没有解决。 https://swift.libhunt.com/realm-cocoa-changelog?page=4
我也尝试过重置集成状态:

pod cache clean Realm
pod cache clean RealmSwift
pod deintegrate || rm -rf Pods
pod install --verbose
rm -rf ~/Library/Developer/Xcode/DerivedData

我的版本信息:

tee /dev/tty | pbcopy
ProductName:    macOS
ProductVersion: 11.1
BuildVersion:   20C69
/Applications/Xcode.app/Contents/Developer
Xcode 12.4
Build version 12D4e
/Users/Paul/.rvm/rubies/ruby-2.4.1/bin/pod 
1.10.1
Realm (10.5.1)
RealmSwift (10.5.1)
/bin/bash
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20)
/usr/bin/git
git version 2.24.3 (Apple Git-128)

我的 Pod 文件:

# Uncomment the next line to define a global platform for your project
 platform :ios, '12.0'

 target 'Vending Receipt' do
 # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
 use_frameworks!

 # Pods for Vending Receipt
 pod 'Realm'
 pod 'RealmSwift' #, :git => 'https://github.com/realm/realm-cocoa.git', :branch => 'master'
 pod 'BTNavigationDropdownMenu'
 pod 'SCLAlertView', :git => 'https://github.com/vikmeup/SCLAlertView-Swift.git'

   target 'Vending ReceiptTests' do 
      inherit! :search_paths
 use_frameworks!
     # Pods for testing
 pod 'Realm'
 pod 'RealmSwift' #, :git => 'https://github.com/realm/realm-cocoa.git', :branch => 'master'
 pod 'BTNavigationDropdownMenu'
 pod 'SCLAlertView', :git => 'https://github.com/vikmeup/SCLAlertView-Swift.git'
   end
 end


 post_install do |installer|
      installer.pods_project.targets.each do |target|
          target.build_configurations.each do |config|
              config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
              config.build_settings['EXCLUDED_ARCHS[sdk=watchsimulator*]'] = 'arm64'
              config.build_settings['EXCLUDED_ARCHS[sdk=appletvsimulator*]'] = 'arm64'
             config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
          end
      end
  end

崩溃日志如下:

致命错误:“试试!”表达式意外引发错误:Error Domain=io.realm Code=6 "Opening Realm files of format version 5 is not supported by this version of Realm" UserInfo={Error Code=6, NSFilePath=/var/mobile/Containers/Data /Application/04864A2A-4605-49B2-893F-15F76F60DD9B/Documents/default.realm, Underlying=数据库有不支持的版本 (5),无法升级 异常回溯:

0 领域 0x000000010104e4ac _ZN5realm2DB7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_9DBOptionsE + 5356 1 领域 0x0000000101050694 _ZN5realm2DB4openERNS_11ReplicationENS_9DBOptionsE + 244

2 领域 0x000000010105517c _ZN5realm2DB6createERNS_11ReplicationENS_9DBOptionsE + 392

3 领域 0x0000000100b5cf40 _ZN5realm5_impl16RealmCoordinator7open_dbEv + 992

4 领域 0x0000000100b5c148 _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_5Realm6ConfigERNSt3__110shared_ptrIS2_EENS_4util8OptionalINS_9VersionIDEEERNS8_17CheckedUniqueLockE + 68

5 领域 0x0000000100b5bf64 _ZN5realm5_impl16RealmCoordinator9get_realmENS_5Realm6ConfigENS_4util8OptionalINS_9VersionIDEEE + 668

6 领域 0x0000000100e4f204 _ZN5realm5Realm16get_shared_realmENS0_6ConfigE + 176

7 领域 0x0000000100db93d4 +[RLMRealm realmWithConfiguration:queue:error:] + 1796

8 RealmSwift 0x0000000102a6f478 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 156

9 RealmSwift 0x0000000102ac8734 $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 216

10 销售收据 0x000000010050d0cc $s15Vending_Receipt0B7StorageC11getReceipts_5sort15sort29ascending10RealmSwift7ResultsVyAA0B0CGSS_S2SSbtF + 1572

11 销售收据 0x00000001004e4868 $s15Vending_Receipt14SearchReceiptsC11UpdateTableyyF + 1980

12 销售收据 0x00000001004e11d0 $s15Vending_Receipt14SearchReceiptsC11viewDidLoadyyF + 5768

13 销售收据 0x00000001004e1250 $s15Vending_Receipt14SearchReceiptsC11viewDidLoadyyFTo + 32

14 UIKitCore 0x00000001a72f2e50 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4623952

15 UIKitCore 0x00000001a72f7408 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4641800

16 UIKitCore 0x00000001a72f77e8 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4642792

17 UIKitCore 0x00000001a722b738 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 3807032

18 UIKitCore 0x00000001a723fbb0 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 3890096

19 UIKitCore 0x00000001a7240fe0 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 3895264

20 UIKitCore 0x00000001a7223e78 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 3776120

21 UIKitCore 0x00000001a7ec2398 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 17007512

22 石英核心 0x00000001a83c7df4 461501DD-204F-3516-9F5D-BDD0BA19FDA1 + 1400308

23 石英核心 0x00000001a83ce398 461501DD-204F-3516-9F5D-BDD0BA19FDA1 + 1426328

24 石英核心 0x00000001a83d96e8 461501DD-204F-3516-9F5D-BDD0BA19FDA1 + 1472232

25 石英核心 0x00000001a8324d7c 461501DD-204F-3516-9F5D-BDD0BA19FDA1 + 732540

26 石英核心 0x00000001a834ef40 461501DD-204F-3516-9F5D-BDD0BA19FDA1 + 905024

27 UIKitCore 0x00000001a79b6d8c CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 11718028

28 UIKitCore 0x00000001a7a5dac4 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 12401348

29 UIKitCore 0x00000001a7a54afc CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 12364540

30 核心基础 0x00000001a50cdbf0 F3021642-E3C0-33F8-9911-DD303A6056D0 + 633840

31 核心基础 0x00000001a50cdaf0 F3021642-E3C0-33F8-9911-DD303A6056D0 + 633584

32 核心基础 0x00000001a50cce38 F3021642-E3C0-33F8-9911-DD303A6056D0 + 630328

33 核心基础 0x00000001a50c73e0 F3021642-E3C0-33F8-9911-DD303A6056D0 + 607200

34 核心基础 0x00000001a50c6ba0 CFRunLoopRunSpecific + 572

35 图形服务 0x00000001bbe2f598 GSEventRunModal + 160

36 UIKitCore 0x00000001a79b82f4 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 11723508

37 UIKitCore 0x00000001a79bd874 UIApplicationMain + 164

38 销售收据 0x00000001004d3444 主要 + 88

39 libdyld.dylib 0x00000001a4da5568 0B475C78-3C12-3121-B7F8-2B95B83DAF44 + 5480, NSLocalizedDescription=此版本的 Realm 不支持打开格式版本 5 的 Realm 文件}:文件 Vending_Receipt/ReceiptModel.swift,第 52 行 2021-02-01 15:16:21.102889-0600 售货收据 [558:58472] 致命错误:“尝试!”表达式意外引发错误:Error Domain=io.realm Code=6 "Opening Realm files of format version 5 is not supported by this version of Realm" UserInfo={Error Code=6, NSFilePath=/var/mobile/Containers/Data /Application/04864A2A-4605-49B2-893F-15F76F60DD9B/Documents/default.realm, Underlying=数据库的版本不受支持 (5),无法升级

【问题讨论】:

  • 无需深入研究,Realm 不是直接的,向后兼容,但可以升级 Realm 文件。但是,到目前为止,我们不知道您做了什么——您有什么版本的 SDK?你使用的是什么版本的 Realm Studio? podfile 中指定的内容。你选择了领域文件,用领域工作室打开并告诉它升级吗?您问题中的大部分内容都不相关 - 我们需要其他详细信息来提供帮助。
  • 我使用的是 XCode 12.4 和 swift 5。Realm 文件的架构没有改变。该问题应该在 2021 年 9 月 20 日在 Realm v5.4.1 中得到解决。我安装了最新版本的 Realm,但问题没有解决。 swift.libhunt.com/realm-cocoa-changelog?page=4 我试过也试过重置集成状态: pod cache clean Realm pod cache clean RealmSwift pod deintegrate || rm -rf Pods pod install --verbose rm -rf ~/Library/Developer/Xcode/DerivedData
  • 请详细更新您的问题 - 在 cmets 中代码很难阅读。将这些添加到问题中。 5.4.1 解决了加密领域问题。这似乎不是这里的情况。您能否用您的 PodFile 以及您使用的 SDK 版本更新您的问题?我认为您的 SDK 和领域文件不匹配,因为它尚未升级,但我现在只是猜测。
  • 我建议您使用正式的 RealmSwift 版本更新您的 podfile。你有什么理由想要来自 github 的最新信息吗?
  • 我已经在上面更新了我拥有的所有信息。

标签: swift migration realm


【解决方案1】:

问题已在 Github 上回答:

v5.0.0 不再支持打开由 v3.0.0 之前的版本编写的 Realm 文件。

我们支持从 6+ 迁移,而 5->6 迁移只需重新创建字符串索引。

【讨论】:

    【解决方案2】:

    核心混淆在于措辞Realm files of format version 5

    文件格式版本Realm SDK版本不同。

    不幸的是,我认为这种版本对应关系在任何地方都没有明确记录。

    changelog 中搜索格式是我知道的唯一方法。

    一个重要的版本可能修复了你的升级问题10.7.1,它恢复了对从文件格式 5 (Realm Cocoa 1.x) 升级文件的支持

    来自my sheet,其中有更多细节:

    • SDK 10.8.0 生成格式为 v22 的领域
    • SDK 10.0.0 生成格式为 v11 的领域
    • SDK 5.4.0 也生成格式为 v11 的领域(MongoDB 独立之前的最后一个?)
    • SDK 2.4 ... 2.10 格式 6
    • SDK 1.x 格式 5

    【讨论】:

    • Note 10.7.1 在提出这个问题大约 5 周后修复了兼容性迁移问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多