Incorrect date value '0000-00-00' for DATE or DATETIME
When setting a default value for a column of DATE or DATETIME datatype in MySQL, if you use ‘0000-00-00 00:00:00’ as the default value, you might run into this error:
ERROR 1067 (42000): Invalid default value for 'column_name'
Or when inserting value:
ERROR 1292 - Incorrect date value: '0000-00-00'
The reason is, since version 5.7, MySQL enables SQL Strict Mode by default and does not permit ‘0000-00-00’ as a valid date value.
Steps to fix this:
1. Check the MySQL mode
You can see the SQL mode from the MySQL configuration file or run this command:
SELECT @@GLOBAL.sql_mode global, @@SESSION.sql_mode session
2. Disable Strict Mode
If strict mode is enabled, either or both STRICT_TRANS_TABLES
or STRICT_ALL_TABLES
are enabled. So you can disable it by commenting it out from the MySQL configuration file, or running the command:
SET sql_mode = '';
Or
SET GLOBAL sql_mode = '';
3. Restart MySQL
Then restart MySQL and you should be able to use ‘0000-00-00’ as a value for DATE or DATETIME column.
Need a good GUI tool for databases? TablePlus provides a native client that allows you to access and manage Oracle, MySQL, SQL Server, PostgreSQL, and many other databases simultaneously using an intuitive and powerful graphical interface.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?