mysql - 将列修改为 utf8 的语句在使用 (ALTER IGNORE TABLE with MODIFY) 时出错

标签 mysql sql database

我正在将一列更新为 UTF-8,因为我需要输入韩文字符。

最初,我在没有忽略的情况下运行了以下查询,但它通过了一个错误。

ALTER TABLE db_name MODIFY column_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

ERROR 1292 (22007): Incorrect date value: '0000-00-00' for column 'PRDP' at row 199593

我搜索并找到了这个:

MySQL Documentation 5.7 says :

Strict mode affects whether the server permits '0000-00-00' as a valid date: If strict mode is not enabled, '0000-00-00' is permitted and inserts produce no warning. If strict mode is enabled, '0000-00-00' is not permitted and inserts produce an error, unless IGNORE is given as well. For INSERT IGNORE and UPDATE IGNORE, '0000-00-00' is permitted and inserts produce a warning.

当我用 IGNORE 运行它时,它给了我这个:

ALTER IGNORE TABLE db_name MODIFY column_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IGNORE TABLE db_name MODIFY column_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4' at line 1

我在 sql 语法验证器 (eversql) 上检查了该语句,但没有发现该错误。

请帮忙!

最佳答案

没有ALTER IGNORE TABLE 语法。请参阅文档:https://dev.mysql.com/doc/refman/5.7/en/alter-table.html

EverSQL 显然在验证 MySQL 中不存在的语法。

您链接到的 SQL 模式文档引用了 INSERT IGNORE 语句。

要解决您的错误,您有两种选择:

  • 在运行 ALTER TABLE 之前,将所有日期值(如“0000-00-00”)替换为有效日期,否则为 NULL。

  • 至少在运行 ALTER TABLE 的 session 中禁用 sql_mode 中的严格选项。

关于mysql - 将列修改为 utf8 的语句在使用 (ALTER IGNORE TABLE with MODIFY) 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54186445/

相关文章:

java 和 sql 到 JList

sql - 无法在 jsonb 对象字段中搜索文本

mysql - 查询 : How to obtain the most recent message per one user conversations?

SQL 'arrays' 重复使用 IN 比较

mysql - SQL 查询查找跨表的最新事件

database - TClientDataSet:如何在数据库结构发生变化时保持本地数据的保存和可用

php - 在 PHP 中嵌套 SQL 查询

MySQL远程数据库服务器连接失败

mysql - PHP "UPDATE SET WHERE"没有抛出任何错误,但不起作用

php - MySQL/PHP更新查询错误