Sqlite / SQLAlchemy: how to enforce Foreign Keys?

Posted by Nick Perkins on Stack Overflow See other posts from Stack Overflow or by Nick Perkins
Published on 2010-04-10T21:07:15Z Indexed on 2010/04/10 21:13 UTC
Read the original article Hit count: 408

Filed under:
|
|
|

The new version of SQLite has the ability to enforce Foreign Key constraints, but for the sake of backwards-compatibility, you have to turn it on for each database connection separately!

sqlite> PRAGMA foreign_keys = ON;

I am using SQLAlchemy -- how can I make sure this always gets turned on? What I have tried is this:

engine = sqlalchemy.create_engine('sqlite:///:memory:', echo=True)
engine.execute('pragma foreign_keys=on')

...but it is not working!...What am I missing?

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy