错误 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_at
和 updated_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';
相关文章