MySQL5.7 datetime无法设置默认值为0

在mysql5.7以上版本中,如果datetime默认值为0,则会出现下面的错误:

ERROR 1067 (42000) at line xxx: Invalid default value for 'xxx'

这是因为mysql5.7调整了校验规则,修改一下/etc/mysql/my.cnf配置文件就可以了

[mysqld]
#默认规则
#sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
sql-mode="ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

然后重启mysql就可以啦。

Leave a Reply

Your email address will not be published. Required fields are marked *

*