我正在将一列从 text 更改为 varchar 列。
+------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| ID | bigint(19) | NO | PRI | NULL | |
| STATUS | varchar(120) | YES | | NULL | |
| PRIORITY | varchar(120) | YES | | NULL | |
| DESCRIPTION | text | YES | | NULL | |
当我执行下面的查询时,
alter table StatInfo modify column DESCRIPTION varchar(255) NULL;
它说 错误 1406 (22001):第 7 行“描述”列的数据太长
它不会截断列中的值并更改表,为什么?。在旧版本中它可以工作。
最佳答案
可能你需要检查sql模式,如果它严格那么它会显示这个错误
When you change a data type using CHANGE or MODIFY, MySQL tries to convert existing column values to the new type as well as possible.
Warning This conversion may result in alteration of data. For example, if you shorten a string column, values may be truncated. To prevent the operation from succeeding if conversions to the new data type would result in loss of data, enable strict SQL mode before using ALTER TABLE (see Section 5.1.6, “Server SQL Modes”).
关于MySQL : Data too long for column on alter table modify column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6679787/