我正在尝试运行一个脚本来修改数据库,这个查询
ALTER TABLE cmContentVersion CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
Run Code Online (Sandbox Code Playgroud)
给出这个错误
ERROR 1067 (42000) at line 68: Invalid default value for 'modifiedDateTime'
Warning (Code 1264): Out of range value for column 'modifiedDateTime' at row 1
Error (Code 1067): Invalid default value for 'modifiedDateTime'
Run Code Online (Sandbox Code Playgroud)
该列modifiedDateTime
被定义为
`modifiedDateTime` datetime NOT NULL default '0000-00-00 00:00:00',
Run Code Online (Sandbox Code Playgroud)
问题:在使用 utf8_general_ci 时,是否有可以替换的有效“无效”默认值0000-00-00 00:00:00
。或者我是否必须告诉开发人员停止依赖他们代码中的“无效日期”?
Tec*_*url 15
与字符集相比,这看起来更像是 SQL 模式问题。严格模式(更具体地说,NO_ZERO_DATE 是严格模式的一部分)如果在打开严格模式之前创建的表的默认日期全为零,则通常会引发该错误。
我们使用的(对于类似的修改日期列)是“1970-01-01 00:00:01”。
在稍微相关的说明中,我们对这些列(以及创建时间)使用时间戳。占用一半的存储空间,访问速度更快。