SQLite3 in Python 2.7 Rejecting Foreign Key Insert
rosuav at gmail.com
Mon Nov 24 05:49:25 CET 2014
On Mon, Nov 24, 2014 at 1:22 PM, llanitedave
<llanitedave at birdandflower.com> wrote:
> I recreated the table and put the foreign key reference directly into the field definition:
> "of_borehole TEXT NOT NULL REFERENCES borehole,"
> This is a valid alternative according to the SQLite3 docs, if you don't explicitly define the field name then it references to the primary key that already exists in the referenced table.
> And that's all I had to do. Strange, but it did the trick.
That's also perfectly valid according to the SQL spec. I prefer to put
the foreign key up there where possible (obviously it's not possible
with a multi-column FK, but those aren't common). Strange that the
other form doesn't work.
More information about the Python-list