Can Alembic Autogenerate column alterations?

Dexter picture Dexter · Jun 18, 2013 · Viewed 7.7k times · Source

I was able to use alembic --autogenerate for when adding / removing columns.

However, when I wanted to modify for example a "url" column from 200 characters to 2000 characters, it doesn't detect the change.

How can I make Alembic (using SQLAlchemy), detect changes and autogenerate scripts to my model's "sizes" of various columns and create "alter_column" commands for PostgreSQL ??

Edit:

Why doesn't alembic automatically add:

op.alter_column('mytable', 'url', type_=sa.String(2000), existing_type=sa.String(length=200), nullable=True)

Answer

Dexter picture Dexter · Jun 18, 2013

Looks like I found the answer on reddit's /r/flask.

http://www.reddit.com/r/flask/comments/1glejl/alembic_autogenerate_column_changes/cale9o0

Just add "compare_type=True" to context.configure() parameters inside your env.py's "run_migrations_online" function.

    context.configure(
                connection=connection,
                target_metadata=target_metadata,
                compare_type=True
                )