ios - 更新现有实体时核心数据模型配置不兼容

标签 ios swift sqlite core-data

我有一个核心数据模型,它向一个实体添加了一个属性。它迁移得很好,我可以毫无问题地向该实体添加新对象。但是,当我尝试向不同实体中的另一个对象添加新关系时,出现了这个 fatal error 。

Unresolved error Error Domain=NSCocoaErrorDomain Code=134020 "The model configuration used to open the store is incompatible with the one that was used to create the store." UserInfo={problemObject=<Order: 0x1702a5a00> (entity: Order; id: 0x170431980 <x-coredata:///Order/t38B0CF1D-437E-44AE-B833-D10B5AD584535> ; data: {
    collection = "0xd000000000040004 <x-coredata://D29044CF-B9FB-4D26-9FB3-96FFEE919BD0/Collection/p1>";
    displayOrder = 9999;
    filterUser = "0xd000000000100008 <x-coredata://22E973D7-62F3-4F8F-B85B-CF12DFB8EFD7/FilterUser/p4>";
    quantity = 1;
    size = 1;
}), NSUnderlyingException=Can't resolve how to assign objects to stores; some objects may have been assigned to stores; use [[managedObject objectID] persistentStore] to find out what is going where now; use [managedObjectContext assignObject:toStore:] to straighten things out}, [AnyHashable("problemObject"): <Order: 0x1702a5a00> (entity: Order; id: 0x170431980 <x-coredata:///Order/t38B0CF1D-437E-44AE-B833-D10B5AD5845

如果我向实体添加一个新对象,那么与它的关系就可以正常工作,事实上,现有对象上的现有关系也可以工作,只是新的关系。我一辈子都弄不明白发生了什么。

最佳答案

发现了一些问题。

我在 iOS 10/macOS 10.12 中迁移到了新的 NSPersistentContainer。默认情况下它会添加默认配置,所以即使我添加了自己的配置,新的保存也会转到“默认”而不是正确的配置。现在一切正常,但只能从第二次启动开始,因为第一次配置的名称不正确。

关于ios - 更新现有实体时核心数据模型配置不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39053565/

相关文章:

ios - 在表格 View 中使用 segues 和动态单元格进行邮件应用程序中的导航?

ios - 以编程方式从 iphone 调用 USSD 代码

ios - 为什么我登录的 segue 不起作用?

swift - RxSwift。 Observable<Void> 使用什么?

java - 如何对 Db 的列求和

android - 如何从 Android 手机与服务器的数据库通信?

ios - 比较 If 中的枚举类型

swift - 来自数组元素的 NSPredicate IN 查询

ios - 如何配合swift/xctest点击iOS主屏幕上的某个点

python - 使用python将数据从xml文件填充到sqlite数据库