错误 1067 (42000):“created_at"的默认值无效 [英] ERROR 1067 (42000): Invalid default value for 'created_at'

查看:44
本文介绍了错误 1067 (42000):“created_at"的默认值无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图改变表格时,它显示了错误:

When I tried to alter the table it showed the error:

ERROR 1067 (42000): Invalid default value for 'created_at'

我用谷歌搜索了这个错误,但我发现的只是他们试图改变时间戳所以它发生了.但是,在这里我尝试添加一个新列,但出现此错误:

I googled for this error but all I found was as if they tried to alter the timestamp so it occurred. However here I am trying to add a new column and I am getting this error:

mysql> ALTER TABLE investments ADD bank TEXT;
ERROR 1067 (42000): Invalid default value for 'created_at'

我的表的最后两列是 created_atupdated_at.

and my table's last two columns are created_at and updated_at.

这是我的表结构:

推荐答案

问题出在sql_modes.请通过命令检查您当前的 sql_modes:

The problem is because of sql_modes. Please check your current sql_modes by command:

show variables like 'sql_mode' ; 

并删除 sql_mode "NO_ZERO_IN_DATE,NO_ZERO_DATE" 以使其工作.这是mysql新版本默认的sql_mode.

And remove the sql_mode "NO_ZERO_IN_DATE,NO_ZERO_DATE" to make it work. This is the default sql_mode in mysql new versions.

您可以通过命令全局设置 sql_mode 为 root:

You can set sql_mode globally as root by command:

set global sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

这篇关于错误 1067 (42000):“created_at"的默认值无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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