code: def set_sqlite_pragma(dbapi_connection, connection_record):
      
      import sqlite3
      if dbapi_connection.__class__ is sqlite3.Connection:
          cursor = dbapi_connection.cursor()
          cursor.execute("PRAGMA foreign_keys=ON")
          cursor.close()
docs: Allows foreign keys to work in sqlite.