Thanks and best regards!
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
......
from sqlalchemy.engine import Engine
from sqlalchemy import event
@event.listens_for(Engine, "connect")
def set_sqlite_pragma(dbapi_connection, connection_record):
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()
def run_migrations_offline():
...
g
Then I ran 'alembic revision --autogenerate' and 'alembic upgrade head' commands. My testing tables were created as usual. When I logged in sqlite by 'sqlite3 mydb', and checked 'PRAGMA foreign_keys', it is still 0. There is no change yet. What is wrong?
Thanks a lot!
Thanks a lot!
from sqlalchemy.engine import Engine
from sqlalchemy import event
@event.listens_for(Engine, "connect")
def set_sqlite_pragma(dbapi_connection, connection_record):
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()
then insert a couple rows to both user and addresses tables.
I didn't insert user id '3', however I could insert foreign key user id '2' into addresses table. So
foreign key constraint was not enforced. I am using
>>> sqlalchemy.__version__
'0.7.8'