[Err] 1293 – Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
字面翻译:不正确的表定义;在DEFAULT或ON UPDATE子句中只能有一个带有CURRENT_TIMESTAMP的时间戳列
执行如下sql:报错
CREATE TABLE `tb_itemcode_list` ( `tbid` int(11) unsigned NOT NULL AUTO_INCREMENT, `itemcode` varchar(100) NOT NULL COMMENT '商品编码', `number` int(20) NOT NULL DEFAULT '0' COMMENT '数量', `remark` text COMMENT '备注', `createtime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, `edit_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `warehouse_id` int(10) DEFAULT NULL, `position_id` int(10) DEFAULT NULL, PRIMARY KEY (`tbid`) ) ENGINE=InnoDB AUTO_INCREMENT=456 DEFAULT CHARSET=utf8;
表中出现多个timestamp并设置为current_timestamp的时候报错
Incorrect table definition; there can be only oneTIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATEclause
原因是当你给一个timestamp设置为on updatecurrent_timestamp的时候,其他的timestamp字段需要显式设定default值
但是如果你有两个timestamp字段,但是只把第一个设定为current_timestamp而第二个没有设定默认值,MySQL能成功建表,但是反过来就不行。
修改后:成功执行
CREATE TABLE `tb_itemcode_list` ( `tbid` int(11) unsigned NOT NULL AUTO_INCREMENT, `itemcode` varchar(100) NOT NULL COMMENT '商品编码', `number` int(20) NOT NULL DEFAULT '0' COMMENT '数量', `remark` text COMMENT '备注', `createtime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, `edit_time` timestamp NULL DEFAULT NULL, -- 去除了 ON UPDATE CURRENT_TIMESTAM `warehouse_id` int(10) DEFAULT NULL, `position_id` int(10) DEFAULT NULL, PRIMARY KEY (`tbid`) ) ENGINE=InnoDB AUTO_INCREMENT=456 DEFAULT CHARSET=utf8; 或: CREATE TABLE `tb_itemcode_list` ( `tbid` int(11) unsigned NOT NULL AUTO_INCREMENT, `itemcode` varchar(100) NOT NULL COMMENT '商品编码', `number` int(20) NOT NULL DEFAULT '0' COMMENT '数量', `remark` text COMMENT '备注', `createtime` datetime NOT NULL COMMENT '创建时间', `edit_time` timestamp not null default CURRENT_TIMESTAMP COMMENT '编辑时间', `warehouse_id` int(10) DEFAULT NULL, `position_id` int(10) DEFAULT NULL, PRIMARY KEY (`tbid`) ) ENGINE=InnoDB AUTO_INCREMENT=456 DEFAULT CHARSET=utf8;