MySQL : Data too long for column on alter table modify column

标签 mysql alter-table

我正在将一列从 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”).

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

关于MySQL : Data too long for column on alter table modify column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6679787/

相关文章:

MySQL优化几何查询

sql-server - 如果名称遵循 SQL Server 中的特定模式,则删除表中的所有列

php - 我想在 php 中更改表,但我的代码不起作用

database - 将集群添加到oracle中的现有表

php - 变量未传递给 sql 查询

java - 受影响的行数, SQL

mysql - Mailchimp 从 mailchimp 更新到 mysql

mysql - 查询更新MYSQL数据库中的数据,在表1中查找,在表2中更新,如何实现?

MySQL 表引擎未更新(或更新未反射(reflect))

MySQL Workbench 删除之前为表定义的触发器