[odb-users] Debugging "FOREIGN KEY constraint failed"
Boris Kolpackov
boris at codesynthesis.com
Fri Aug 21 12:15:25 EDT 2015
Hi Andrew,
Andrew Cunningham <andrew at a-cunningham.com> writes:
> I am getting the "FOREIGN KEY constraint failed" exception on commit
> (SQLite). Clearly I have not 'persisted' a child object somewhere,
> but the exception gives no information. I have a large number of
> object types, so this is pretty tricky to find. What are the
> debugging tips for finding my error.
Hm, this is what I would do, assuming that you are trying to persist
all related object before the object itself.
1. Switch to the immediate foreign keys (--fkeys-deferrable-mode options).
Now you will get an exception immediately after the persist() call that
has violated relationships.
2. If #1 is not sufficient, then enable statement tracing. This will
give you more precise view of what has been persisted so far.
Boris
More information about the odb-users
mailing list