Rookie question :sweat_smile:
I recently changed a column length in the column_metadata table:
from

    type = Column(db.String(255), nullable=True)

to

    type = Column(db.String(4096), nullable=True)

How do I use alembic to generate a migration script under migrations/versions/?

Answering my own question:
By default, Alembic doesn’t detect changes like this. I need to add compare_type=True in migrations/env.py:

  diff --git a/migrations/env.py b/migrations/env.py
  index 45938160..8d8a3fa1 100755
  --- a/migrations/env.py
  +++ b/migrations/env.py
  @@ -41,7 +41,7 @@ def run_migrations_offline():

       """
       url = config.get_main_option("sqlalchemy.url")
  -    context.configure(url=url)
  +    context.configure(url=url, compare_type=True)

       with context.begin_transaction():
           context.run_migrations()
  @@ -73,7 +73,8 @@ def run_migrations_online():
       context.configure(connection=connection,
                         target_metadata=target_metadata,
                         process_revision_directives=process_revision_directives,
  -                      **current_app.extensions['migrate'].configure_args)
  +                      **current_app.extensions['migrate'].configure_args,
  +                      compare_type=True)

And then run ./manage db migrate

1 Like