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)
You can do something like this: DELETE FROM alembic_version WHERE version_num='3aae6532b560'; INSERT INTO alembic_version VALUES ('3aae6532b560'); Above query could be done in one query by limiting number of deleted rows, but limiting within DELETE query is different between different databases engines.
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 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With