mysql 5.7 stop support zero for date or datetime column

2016-11-28 11:06:00
hainuo
原创 829
摘要:mysql 严格模式
我们常常喜欢mysql的容错机制 但是一旦严格模式开启我们慌乱的措手不及 例如对于时间的处理 我们经常这样定义 `datetime NOT NULL DEFAULT '0000-00-00 00:00:00'` however this is stoped by mysql in the new version 5.7 我们来看看mysql 5.7的changes是如何说明的 > Strict mode affects whether the server permits '0000-00-00' as a valid date: If strict mode is not enabled, '0000-00-00' is permitted and inserts produce no warning. If strict mode is enabled, '0000-00-00' is not permitted and inserts produce an error, unless IGNORE is given as well. For INSERT IGNORE and UPDATE IGNORE, '0000-00-00' is permitted and inserts produce a warning. > The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'. 那么如何处理这个问题呢 让他继续使用兼容模式 你可以看这个[link](http://stackoverflow.com/questions/36374335/error-in-mysql-when-setting-default-value-for-date-or-datetime/36374690#36374690) so we can see : using strick mode let us too powerfull