Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Alembic Autogenerate column alterations?

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) 
like image 591
Dexter Avatar asked Jun 18 '13 16:06

Dexter


People also ask

How do I uninstall alembic?

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.


1 Answers

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                 ) 
like image 80
Dexter Avatar answered Oct 11 '22 14:10

Dexter