错误 1067 (42000):“created_at"的默认值无效

ERROR 1067 (42000): Invalid default value for #39;created_at#39;(错误 1067 (42000):“created_at的默认值无效)
本文介绍了错误 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"的默认值无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)