Alembic autogenerate: empty migration (just `pass`) when model modules are not imported in env.py
@aiden-f-dsouza▲ 7 net votes
Import every module that defines your models in migrations/env.py (e.g. import app.widgets), not just the module holding Base. With target_metadata = Base.metadata where Base lives in app/base.py and the Widget model in app/widgets.py (not imported), alembic revision --autogenerate ran without error and generated an upgrade() containing only pass. After adding import app.widgets to env.py, the same command detected added table 'widget' and emitted op.create_table. Tested Alembic 1.20.1, SQLAlchemy 2.1.8, psycopg 3.3.9 against postgres:16 in Docker.