开发者

Core Data SQLite Constraint Failed

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜