You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS 17下Core Data轻量迁移部分用户失败问题求助

iOS 17下Core Data轻量迁移异常问题

问题详情

自iOS 17发布后,Core Data轻量迁移出现异常。当前NSPersistentStoreCoordinator使用的配置选项为:

[NSMigratePersistentStoresAutomaticallyOption: true as AnyObject, NSInferMappingModelAutomaticallyOption: true as AnyObject, NSSQLitePragmasOption: ["journal_mode": "DELETE"] as AnyObject]

添加持久化存储的代码如下:

try persistentCoordinator.addPersistentStore(ofType: NSInMemoryStoreType, configurationName: "InMemoryStore", at: nil, options: myOptions)
try persistentCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: "PersistentStore", at: myGroupURL, options: myOptions)

若添加存储失败,会删除数据库并重建。此前修改.xcdatamodel时未创建版本,iOS 17之前轻量迁移一直正常,但现在部分用户出现迁移失败。将.xcdatamodel从版本1更新到2后,部分用户收到错误:

An error occurred during persistent store migration., reason: Failed to open the store, underlyingReason: The model used to open the store is incompatible with the one used to create the store

此外,NSPersistentStoreCoordinator的MOM合并了另外两个模型,但这两个模型自问题出现后未做任何修改。问题出现在为实体添加属性或新增实体时,且排除这类操作直接导致的明确错误(若为此类原因,错误信息会有明确说明)。

咨询内容

  1. iOS 17是否有相关变更导致此问题?
  2. 以下方案是否可行,或有其他解决办法:
    • 为.xcdatamodel添加版本?尽管苹果文档未将其列为必需项
    • 从NSPersistentStoreCoordinator中移除另外两个模型?
    • 其他可行方案?

内容的提问来源于stack exchange,提问作者Gabriel Sória

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 13:57:36