SQLite3 in Python 2.7 Rejecting Foreign Key Insert

Chris Angelico rosuav at gmail.com
Sun Nov 23 10:53:16 CET 2014


On Sun, Nov 23, 2014 at 8:40 PM, Jussi Piitulainen
<jpiitula at ling.helsinki.fi> wrote:
> Chris Angelico writes:
>> On Sun, Nov 23, 2014 at 7:21 PM, Frank Millman wrote:
>>
>> > To enable them, add the following -
>> >
>> > pragma foreign_keys = on;
>> >
>> > It works for me.
>>
>> Thanks, I went poking around briefly but didn't find that pragma.
>
> I didn't notice a pointer to the relevant documentation in this thread
> yet. So here, and in the rest of that page:
>
>     <http://www.sqlite.org/foreignkeys.html#fk_enable>

>From that page:

"""Foreign key constraints are disabled by default (for backwards
compatibility), so must be enabled separately for each database
connection. (Note, however, that future releases of SQLite might
change so that foreign key constraints enabled by default. Careful
developers will not make any assumptions about whether or not foreign
keys are enabled by default but will instead enable or disable them as
necessary.)"""

That explains it. Putting the "backwards" into "backwards
compatibility", but understandable, at least. I'm pointing all the
people I know to this page; just enable the things and then you can
actually trust stuff.

ChrisA



More information about the Python-list mailing list