Bug #106791 | ALTER TABLE MODIFY COLUMN reinitialize default properties | ||
---|---|---|---|
Submitted: | 22 Mar 2022 8:45 | Modified: | 22 Mar 2022 9:21 |
Reporter: | STEINMETZ Catherine | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: DDL | Severity: | S2 (Serious) |
Version: | 8.0.20 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[22 Mar 2022 8:45]
STEINMETZ Catherine
[22 Mar 2022 9:21]
MySQL Verification Team
Hello STEINMETZ Catherine, Thank you for the report and feedback. Imho this is expected and documented behavior. Quoting from official documentation page - For column definition changes using CHANGE or MODIFY, the definition must include the data type and all attributes that should apply to the new column, other than index attributes such as PRIMARY KEY or UNIQUE. Attributes present in the original definition but not specified for the new definition are not carried forward. Suppose that a column col1 is defined as INT UNSIGNED DEFAULT 1 COMMENT 'my column' and you modify the column as follows, intending to change only INT to BIGINT: ALTER TABLE t1 MODIFY col1 BIGINT; That statement changes the data type from INT to BIGINT, but it also drops the UNSIGNED, DEFAULT, and COMMENT attributes. To retain them, the statement must include them explicitly: ALTER TABLE t1 MODIFY col1 BIGINT UNSIGNED DEFAULT 1 COMMENT 'my column'; For data type changes using CHANGE or MODIFY, MySQL tries to convert existing column values to the new type as well as possible. Please see https://dev.mysql.com/doc/refman/8.0/en/alter-table.html -- create table test (a int primary key auto_increment, b varchar(30) not null default 'DEFAULT VALUE'); show create table test; =================================== CREATE TABLE `test` ( `a` int NOT NULL AUTO_INCREMENT, `b` varchar(30) NOT NULL DEFAULT 'DEFAULT VALUE', PRIMARY KEY (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci alter table test modify b varchar(40) not null default 'DEFAULT VALUE'; show create table test; CREATE TABLE `test` ( `a` int NOT NULL AUTO_INCREMENT, `b` varchar(40) NOT NULL DEFAULT 'DEFAULT VALUE', PRIMARY KEY (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; regards, Umesh