-
-
Notifications
You must be signed in to change notification settings - Fork 305
Closed
Labels
Description
Versions:
Python: 3.7.4 (Linux/x64/conda)
Alembic: 1.0.11
SQLAlchemy: 1.3.5
MariaDB: 10.3.13
Steps to reproduce
- Have a table
storage_drivewith Integer columndrive_partition, nullable, and commentIf more than one partition, the 1-based partition index. - In alembic
upgrade()migration function, issue the following command to change the column name topartition_:
op.alter_column(
"storage_drive",
"drive_partition",
existing_type=sa.Integer(),
existing_comment="If more than one partition, the 1-based partition index.",
new_column_name="partition_",
)Expected Result:
Column is renamed to partition_ and the comment is preserved.
Actual Result:
Column is renamed to partition_ and the comment disappears.
Investigation
- I used my interactive debugger to step through the
alter_tablecommand, and eventually got toalembic/ddl/mysql.pyline 47. - Since
name is not Noneevaluated toTrue, the call toMySQLChangeColumnat line 51 was executed. - Notably, this call does not include the
commentkeyword argument (vs. theMySQLModifyColumncall at line 77), soexisting_commentwas dropped.
Workaround
Add another alter_column call to reinstate the comment.
op.alter_column(
"storage_drive",
"partition_",
existing_type=sa.Integer(),
comment="If more than one partition, the 1-based partition index.",
)