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

查看:268
本文介绍了错误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.

这是我的表结构:

推荐答案

问题是由于 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天全站免登陆