今天执行SQL脚本时出现错误:脚本如下
CREATE TABLE `ab_permission` (
`create_time` timestamp DEFAULT CURRENT_TIMESTAMP,
`update_time` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_uk_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=67 DEFAULT CHARSET=utf8;
[Err] 1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
经过查阅资料发现是自己Mysql版本问题,自己使用的是Mysql5.5,所以出现了问题。
在MySQL 5.5文档有这么一段话:
One TIMESTAMP column in a table can have the current timestamp as the default value for initializing the column, as the auto-update value, or both. It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column.
而在MySQL 5.6.5做出了以下改变:
Previously, at most one TIMESTAMP column per table could be automatically initialized or updated to the current date and time. This restriction has been lifted. Any TIMESTAMP column definition can have any combination of DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses. In addition, these clauses now can be used with DATETIME column definitions. For more information, see Automatic Initialization and Updating for TIMESTAMP and DATETIME.
参考:点击打开链接
本文介绍了在MySQL5.5中执行SQL脚本创建表时遇到的问题:无法同时为两个TIMESTAMP字段设置DEFAULT CURRENT_TIMESTAMP及ON UPDATE CURRENT_TIMESTAMP。文中详细解释了不同MySQL版本对此特性的支持情况,并给出了相应的解决方案。
423

被折叠的 条评论
为什么被折叠?



