Fix SQLAlchemy 2.0 database migration error
- Update migrations/env.py to use SQLAlchemy 2.0 compatible syntax - Import text class from sqlalchemy for executing raw SQL - Convert connection.execute() call to use text() for PRAGMA statements - Fix the database migration error for SQLite foreign keys
This commit is contained in:
parent
20e3b39596
commit
112ebdbf7d
@ -2,7 +2,7 @@ from logging.config import fileConfig
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from alembic import context
|
from alembic import context
|
||||||
from sqlalchemy import engine_from_config, pool
|
from sqlalchemy import engine_from_config, pool, text
|
||||||
|
|
||||||
# Add the parent directory to sys.path
|
# Add the parent directory to sys.path
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||||
@ -78,7 +78,7 @@ def run_migrations_online():
|
|||||||
|
|
||||||
# For SQLite, enable foreign keys
|
# For SQLite, enable foreign keys
|
||||||
if is_sqlite:
|
if is_sqlite:
|
||||||
connection.execute("PRAGMA foreign_keys=ON")
|
connection.execute(text("PRAGMA foreign_keys=ON"))
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
context.run_migrations()
|
context.run_migrations()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user