ERROR 1067 (42000): Invalid default value for #39;created_at#39;(错误 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';
这篇关于错误 1067 (42000):“created_at"的默认值无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:错误 1067 (42000):“created_at"的默认值无效
基础教程推荐
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 无法解决整理冲突 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
