Recently, in one of my project, I am using sqlalchemy for ORM and alembic for migration management.
I have find one annoying problem, that the alembic auto generating only work for one module files.
In the Auto Generating Migrations Document, it says how to configure autogenerate for alembic.
1 | # add your model's MetaData object here |
change to:
1 | from myapp.mymodel import Base |
But this is only for one module file(mymdel in the example), if you have more than one module file, it won’t work.
Here is the workround for multiple models files, improved it based on articles in reference:
1 | from sqlalchemy import engine_from_config, pool, MetaData |
other issues
As I didn’t use any framework, so I need to add the model path to the sys.path to the env.py
1 | # add the model path to sys.path |