我正在将一列更新为 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/