mysql alter table add column before,MySQL ALTER TABLE添加列:另一列错误

本文讨论了在尝试使用ALTER TABLE添加列时遇到的MySQL错误,关于0000-00-00日期值。解决方法可能涉及NO_ZERO_DATE SQL模式设置,以避免使用此非法日期。作者分享了类似经验并提到了检查现有表约束的重要性。
摘要由CSDN通过智能技术生成

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

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.

In addition, not all null date values return error.

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值