there can be only one TIMESTAMP column with CURRENT_TIME

标签:
mysql解决器ddlcurrent_timestampdatetime |
在使用两个环境的msyql,需要复制同一个表时候,复制了一个建表语句,结果发现居然不能执行。
`CREATE_TIME` timestamp NOT NULL DEFAULT
CURRENT_TIMESTAMP COMMENT '创建时间',
`updateBy` varchar(64) DEFAULT NULL COMMENT
'更新者',
`UPDATE_TIME` timestamp NOT NULL DEFAULT
CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`CREATE_TIME` timestamp NOT NULL DEFAULT
CURRENT_TIMESTAMP COMMENT '创建时间',
`updateBy` varchar(64) DEFAULT NULL COMMENT
'更新者',
`UPDATE_TIME` DATETIME NOT NULL COMMENT
'更新时间',
FOR EACH ROW SET NEW.`UPDATE_TIME` =
NOW()
抛出错误:
1293 - Incorrect table definition; there can be only one
TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE
clause
查询资料得知,因为两个mysql版本不一致导致。只能有一个带CURRENT_TIMESTAMP的timestamp列存在,建表语句建立在高版本mysql上,目标库版本较低
http://s8/mw690/0020IfRxzy7hCTxwlKLd7&690can be only one TIMESTAMP column with CURRENT_TIME" TITLE="there can be only one TIMESTAMP column with CURRENT_TIME" />
http://s8/mw690/0020IfRxzy7hCTxrqgnb7&690canbe only one TIMESTAMP column with CURRENT_TIME" TITLE="there can be only one TIMESTAMP column with CURRENT_TIME" />
http://s8/mw690/0020IfRxzy7hCTxrqgnb7&690can
源表建表语句 ---将会报错
CREATE TABLE `stu` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='表';
使用触发器解决,
将目标表修改为
CREATE TABLE `stu` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='表';
DROP TRIGGER IF EXISTS `update_stu_update`;
DELIMITER //
CREATE TRIGGER `update_stu_update` BEFORE UPDATE ON
`test.stu`
//
DELIMITER ;