遇到导入mysql数据库问题
CREATE TABLE `example` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `lastUpdated` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB;
问题
MySQL错误TIMESTAMP column with CURRENT_TIMESTAMP的解决方法_Mysql_脚本之家
ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause.
原因
MySQL错误TIMESTAMP column with CURRENT_TIMESTAMP的解决方法_Mysql_脚本之家
意思是只能有一个带CURRENT_TIMESTAMP的timestamp列存在,但是为什么本地测试却没有任何问题呢,本地测试的机器安装的MySQL版本5.6.13,而生产机器上安装的却是5.5版本,搜索网络后得知这两种版本之间对于timestamp处理的区别在于:
问题方法
CREATE TABLE `example` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `lastUpdated` DATETIME NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; DROP TRIGGER IF EXISTS `update_example_trigger`; DELIMITER // CREATE TRIGGER `update_example_trigger` BEFORE UPDATE ON `example` FOR EACH ROW SET NEW.`lastUpdated` = NOW() // DELIMITER ;