Is there SQLAlchemy automigration tool like South for Django? Is there SQLAlchemy automigration tool like South for Django? database database

Is there SQLAlchemy automigration tool like South for Django?


You can perform automatic migrations with Alembic. I use it in two large-scale projects I am currently working on. The automatic migration generator can recognize:

  • Table additions and removals
  • Column additions and removals
  • Change of nullable status on columns
  • Basic changes in indexes, explicitly-named unique constraints, and foreign keys

(see also: https://alembic.sqlalchemy.org/en/latest/autogenerate.html)

Install alembic

pip install alembic

or (depending on the version of Python you are using):

pip3 install alembic

Configure alembic

Execute the following command in your project:

alembic init alembic

This will set up alembic for your project, in a folder called alembic.

You will then need to edit the generated alembic.ini configuration file.

In the file env.py, tell Alembic where to find SQLAlchemy's metadata object in your project.

(see also: https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file)

Generate the migration

Simply execute the following command line:

alembic revision --autogenerate -m "Message for this migration"

Or even (not recommended):

alembic revision --autogenerate

Upgrade the database

After this, I upgrade the database with this simple command from the folder containing the alembic.ini configuration file:

alembic upgrade head

(see also: http://rodic.fr/blog/automatic-migrations-sqlalchemy-alembic/)


There is Alembic which looks very promising, but the problem is (for now) that the support for SQlite databases is very limited.


No there is none at this moment. Alembic require you to write code regarding adding/deleting/altering table structure or creating/dropping table. So nothing like django south exists for sqlalchemy.