Flask-migrate and changing column type
Just need to add compare_type=True
in the Migrate constructor
from flask_migrate import Migratemigrate = Migrate(compare_type=True)app = Flask(__name__)migrate.init_app(app)
Update:
As expected, this answer is now out of date, please see https://stackoverflow.com/a/52181159/428907 for a real fix!
Original Answer:
Alembic does not recognize things like column type changes when auto-generating revisions by default. When making these more granular changes, you will need to hand-modify the migration to include these changes
e.g., in your migration file
from alembic import opimport sqlalchemy as sadef upgrade(): # ... op.alter_column('downloads', 'size', existing_type=sa.Integer(), type_=sa.BigInteger())def downgrade(): # ... op.alter_column('downloads', 'size', existing_type=sa.BigInteger(), type_=sa.Integer())
For details on the operations, see the operation reference
You can turn on detection of type changes by modifying your env.py and alembic.ini, as seen here
By default, Flask-migrate doesn't track the changes when type of column is changed. One of many ways to achieve this is to set
compare_type=True
Under env.py. e.g. -
context.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, compare_type=True, **current_app.extensions['migrate'].configure_args)