核心数据 SQLite 约束失败

发布于 2024-11-01 14:01:03 字数 756 浏览 2 评论 0原文

当我尝试保存 SQLite 支持的托管对象上下文时,有时会出现错误。

Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x280170 {NSFilePath=/var/mobile/Applications/7773BDBD-C502-4E21-9632-FA36A109BF6E/Documents/Social.sqlite, NSUnderlyingException=error during SQL execution : constraint failed}, { NSFilePath = "/var/mobile/Applications/7773BDBD-C502-4E21-9632-FA36A109BF6E/Documents/Social.sqlite";
NSUnderlyingException = "error during SQL execution : constraint failed";  
} 

二进制数据存储不会发生这种情况,只有当我修改特定实体并在短时间内多次保存上下文时才会发生这种情况。谁能建议一种调试方法?我用 sqlite3 查看了 .sqlite 文件,没有任何内容跳出。我不认为这是一个显式的核心数据约束违规(空要求值等),因为我没有看到二进制存储有错误。该程序很复杂(多个线程中的多个上下文),并且我无法用简单的代码复制错误以在此处显示。关于如何注销核心数据后面的 sqlite 实例有什么想法吗?

I sometimes get an error when I attempt to save a managed object context backed by SQLite.

Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x280170 {NSFilePath=/var/mobile/Applications/7773BDBD-C502-4E21-9632-FA36A109BF6E/Documents/Social.sqlite, NSUnderlyingException=error during SQL execution : constraint failed}, { NSFilePath = "/var/mobile/Applications/7773BDBD-C502-4E21-9632-FA36A109BF6E/Documents/Social.sqlite";
NSUnderlyingException = "error during SQL execution : constraint failed";  
} 

This does not happen with a binary datastore, and only happens when I modify a particular entity and save the context multiple times in a short period. Can anyone suggest a way to debug this? I've looked at the .sqlite file with sqlite3, and nothings jumps out. I don't think that it's an explicit core data constraint violation (null required value or the like) because I see no error with the binary store. The program is complex (multiple contexts in several threads), and I've not been able to duplicate the error in simple code to show here. Any ideas about how to get logging out of the sqlite instance behind core data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

治碍 2024-11-08 14:01:03

难道这个保存是在一个单独的线程的上下文中发生的,该线程不知道它所受的父关系(这就是它对我的理解)。

即父记录已保存到其线程 3 上下文中,然后与主线程上下文合并,但是子记录位于线程 5(或除 3 之外的任何线程)上下文中,它不知道对线程 3 的主上下文。

将该记录插入到线程 5 上下文中将违反引用完整性和关系约束。在这种情况下,只能将记录直接插入到主线程的上下文中。

Could it be that this save is happening either in a context on a separate thread which isn't aware of a parent relationship it is constrained on (that's how it reads to me).

i.e. A parent record has been saved to it's thread 3 context and then merged with the main thread's context, however the child record is on thread 5 (or any thread other than 3) context, which isn't aware of the changes made to the main context by thread 3.

Inserting that record into the thread 5 context would violate referential integrity and the relationship constraints. In this situation it would only be possible to insert the record directly into the main thread's context.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文