
from flask.ext.sqlalchemy import SQLAlchemy

__all__ = ['db']

db = SQLAlchemy()


from flask.ext.sqlalchemy import SQLAlchemy

__all__ = ['db']

db = SQLAlchemy()


# To enable foreign key support in SQLite3
from sqlalchemy import event
from sqlalchemy.engine import Engine
from sqlite3 import Connection as SQLite3Connection


@event.listens_for(Engine, "connect")
def _set_sqlite_pragma(dbapi_connection, connection_record):
    if isinstance(dbapi_connection, SQLite3Connection):
        cursor = dbapi_connection.cursor()
        cursor.execute("PRAGMA foreign_keys=ON;")
        cursor.close()

Fix for SQLite3 foreign keys.
Fix for SQLite3 foreign keys.

  
  from flask.ext.sqlalchemy import SQLAlchemy
  
  __all__ = ['db']
  
  db = SQLAlchemy()
  
+ 
+ # To enable foreign key support in SQLite3
+ from sqlalchemy import event
+ from sqlalchemy.engine import Engine
+ from sqlite3 import Connection as SQLite3Connection
+ 
+ 
+ @event.listens_for(Engine, "connect")
+ def _set_sqlite_pragma(dbapi_connection, connection_record):
+     if isinstance(dbapi_connection, SQLite3Connection):
+         cursor = dbapi_connection.cursor()
+         cursor.execute("PRAGMA foreign_keys=ON;")
+         cursor.close()
+ 
Fix for SQLite3 foreign keys.
## Code Before:

from flask.ext.sqlalchemy import SQLAlchemy

__all__ = ['db']

db = SQLAlchemy()

## Instruction:
Fix for SQLite3 foreign keys.
## Code After:

from flask.ext.sqlalchemy import SQLAlchemy

__all__ = ['db']

db = SQLAlchemy()


# To enable foreign key support in SQLite3
from sqlalchemy import event
from sqlalchemy.engine import Engine
from sqlite3 import Connection as SQLite3Connection


@event.listens_for(Engine, "connect")
def _set_sqlite_pragma(dbapi_connection, connection_record):
    if isinstance(dbapi_connection, SQLite3Connection):
        cursor = dbapi_connection.cursor()
        cursor.execute("PRAGMA foreign_keys=ON;")
        cursor.close()
