Created
January 27, 2015 09:11
-
-
Save lucidfrontier45/7a4989490300d1298ba0 to your computer and use it in GitHub Desktop.
Enforce FK constraint for SQLite with when using flask-sqlalchemy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
app = Flask(__name__) | |
try: | |
app.config.from_object("config") | |
except: | |
pass | |
if app.config["SQLALCHEMY_DATABASE_URI"].startswith("sqlite"): | |
def _fk_pragma_on_connect(dbapi_con, con_record): | |
dbapi_con.execute('pragma foreign_keys=ON') | |
from sqlalchemy import event | |
event.listen(sensing_db.engine, 'connect', _fk_pragma_on_connect) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment