Skip to content

Instantly share code, notes, and snippets.

@robin-wittler
Created January 25, 2012 12:19
Show Gist options
  • Save robin-wittler/1676017 to your computer and use it in GitHub Desktop.
Save robin-wittler/1676017 to your computer and use it in GitHub Desktop.
fix for this
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy.interfaces import PoolListener
class SQLiteForeignKeysListener(PoolListener):
def connect(self, dbapi_con, con_record):
db_cursor = dbapi_con.execute('pragma foreign_keys=ON')
class StrictSQLAlchemy(SQLAlchemy):
def apply_driver_hacks(self, app, info, options):
super(StrictSQLAlchemy, self).apply_driver_hacks(app, info, options)
if info.drivername == 'sqlite':
options.setdefault('listeners', []).append(SQLiteForeignKeysListener())
db = StrictSQLAlchemy(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment