在mysql 5.5.46中有表,在5.6.28中有相同的表.我在mysql 5.5.46上备份数据库,然后在5.6.28上还原它.因此,两台服务器上的表具有相同的结构和相同的数据.
CREATE TABLE `test` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Path` varchar(250) NOT NULL,
`Link` varchar(250) NOT NULL,
`Company` varchar(250) NOT NULL,
`Width` int(11) NOT NULL,
`Height` int(11) NOT NULL,
`View_Count` int(11) NOT NULL DEFAULT '0',
`create_date` datetime NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8
有这样的查询:
insert into test(path,link,company,width,height,view_count)
values('test','test','test',10,10,10)
在mysql 5.5.46上,此查询成功执行,并且create_date值为’0000-00-00 00:00:00′
在mysql 5.6.28上有一个错误字段’Create_Date’没有默认值,并且在逻辑上是因为create_date不为null,所以它没有任何默认值.但是它如何在5.5.46上工作?
解决方法:
根据您提供给我们的信息,您似乎在非严格模式下运行MySQL 5.5.46,但在严格模式下运行MySQL 5.6.28.从MySQL documentation开始:
TIMESTAMP columns declared as NOT NULL and without an explicit DEFAULT clause are treated as having no default value. For inserted rows that specify no explicit value for such a column, the result depends on the SQL mode. If strict SQL mode is enabled, an error occurs. If strict SQL mode is not enabled, the column is assigned the implicit default of ‘0000-00-00 00:00:00’ and a warning occurs. This is similar to how MySQL treats other temporal types such as DATETIME.
您的create_date列的类型为DATETIME,似乎您正在尝试以严格模式在5.6.28数据库中执行INSERT,因此出现错误.
标签:datetime,sql,mysql
来源: https://codeday.me/bug/20191119/2035079.html