Invalid default value for 'create_date' timestamp field

创建表的语句中有这么一句

`create_date` TIMESTAMP NOT NULL DEFAULT  '0000-00-00 00:00:00',

之后就报了这个错误。

That is because of server SQL Mode - NO_ZERO_DATE.
In strict mode, don’t allow ‘0000-00-00’ as a valid date.

TIMESTAMP has a range of ‘1970-01-01 00:00:01’ UTC to ‘2038-01-19 03:14:07’ UTC (see doc). The default value must be within that range.

执行下面的命令可以看到 sql mode

SHOW VARIABLES LIKE 'sql_mode'

If you want to affect on all client, please use “@@global”, for example:

SET @@global.sql_mode ="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";

连接MySQL,在客户端执行上面的命令就可以了。

参考资料

Invalid default value for ‘create_date’ timestamp field

你可能感兴趣的:(Problem,Database)