MySQL ALTER TABLE添加列:另一列错误 [英] MySQL ALTER TABLE add column: error at another column

查看:261
本文介绍了MySQL ALTER TABLE添加列:另一列错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,我有people表,并尝试使用下一条命令运行sql-script:

ok, i have people table and try run sql-script with the next command:

ALTER TABLE `people`
    ADD COLUMN `name_spelling`
    VARCHAR(255) NULL DEFAULT NULL
    AFTER `last_name`;

然后我会得到一个错误:

Then I'll get a error:

[22001][1292] Data truncation: Incorrect date value:
'0000-00-00' for column 'birth_date' at row 35

在此行中birth_dateNULL,但是如果我尝试在此列和行中设置某个日期,例如2016-05-05,然后再将NULL设置回去,则该行的所有工作均正确,但会出错在下一个null日期.

At this row birth_date is NULL, but if I try set some date like 2016-05-05 at this column and row and than set NULL back -- all works is correct at this row, but get error on some next null date.

此外,并非所有null日期值都返回错误.

In addition, not all null date values return error.

推荐答案

也许您的MySQL有一些选择,例如NO_ZERO_DATE SQL模式(我认为这不是唯一可以阻止注册日期的mysql配置).这将阻止您将registry用作值.在我已经创建了一个违反该条件的表之前,这件事发生在我身上.除非您更改值或禁用阻止您将日期设置为0的功能,否则它将不可编辑.

Maybe your MySQL has some option such as the NO_ZERO_DATE SQL mode (I think it's not the only mysql config that prevents 0000-00-00 dates). This would prevent you from using 0000-00-00 as a value. It happened to me before that I had a table already created violating that condition. It will not be editable until you change the value or disable what's preventing you to set 0 dates.

供参考: http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html

这篇关于MySQL ALTER TABLE添加列:另一列错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆