Skip to content

migrate_columns() silently drops NOT NULL constraint on blob columns #1434

@esutlie

Description

@esutlie

migrate_columns() doesn't preserve the NOT NULL constraint when updating column comments. The MODIFY COLUMN statement only includes the type and new comment, so MySQL defaults the column to nullable.

The generated SQL looks like:

ALTER TABLE `db`.`table` MODIFY COLUMN `col` longblob COMMENT ':blob:my comment'

But for columns that were NOT NULL, it should be:

ALTER TABLE `db`.`table` MODIFY COLUMN `col` longblob NOT NULL COMMENT ':blob:my comment'

The root cause is in analyze_columns(). The information_schema.COLUMNS query only fetches COLUMN_NAME, COLUMN_TYPE, DATA_TYPE, COLUMN_COMMENT and doesn't include IS_NULLABLE. So by the time migrate_columns() builds the ALTER TABLE, it has no way to know whether the column was NOT NULL.

The fix would be to add IS_NULLABLE to the query, carry that through to col_info, and conditionally include NOT NULL in the MODIFY COLUMN statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions