Flask-migrate and changing column type

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 op
import sqlalchemy as sa
def 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


Just need to add compare_type=True in the Migrate constructor

from flask_migrate import Migrate
migrate = Migrate(compare_type=True)

app = Flask(__name__)
migrate.init_app(app)