Flask-migrate: renaming columns - not dropping old and creating new

Created on 23 May 2014  路  4Comments  路  Source: miguelgrinberg/Flask-Migrate

How do I tell migrate that I want to rename the columns i.e, issue op.alter_column instead of op.drop(old_column) and op.add_column(new_column), so that the data is preserved?

wontfix

Most helpful comment

As is mentioned in the document and in my tutorials, automatic migration generation is not 100% accurate. The migration scripts are meant to be hand-edited, consider the generated script a starting version. You should _always_ review and correct the generated scripts. Column renames is one example where there is really no safe way for the software to determine that you renamed a column.

All 4 comments

From the Alembic docs:

Autogenerate can not detect:

  • Changes of table name. These will come out as an add/drop of two different tables, and should be hand-edited into a name change instead.
  • Changes of column name. Like table name changes, these are detected as a column add/drop pair, which is not at all the same as a name change.

You should review migrations before running them to ensure correctness, for this reason and others.

As is mentioned in the document and in my tutorials, automatic migration generation is not 100% accurate. The migration scripts are meant to be hand-edited, consider the generated script a starting version. You should _always_ review and correct the generated scripts. Column renames is one example where there is really no safe way for the software to determine that you renamed a column.

Can't this be closed?

Yes, I'm closing.

Was this page helpful?
0 / 5 - 0 ratings