Skip to content

Allow preserve comment on column rename in MySQL #594

@randallpittman

Description

@randallpittman

Versions:
Python: 3.7.4 (Linux/x64/conda)
Alembic: 1.0.11
SQLAlchemy: 1.3.5
MariaDB: 10.3.13

Steps to reproduce

  1. Have a table storage_drive with Integer column drive_partition, nullable, and comment If more than one partition, the 1-based partition index.
  2. In alembic upgrade() migration function, issue the following command to change the column name to partition_:
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_table command, and eventually got to alembic/ddl/mysql.py line 47.
  • Since name is not None evaluated to True , the call to MySQLChangeColumn at line 51 was executed.
  • Notably, this call does not include the comment keyword argument (vs. the MySQLModifyColumn call at line 77), so existing_comment was 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.",
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions