MySQL 5.6.5之前版本不支持多条DEFAULT CURR
创建数据表时失败,提示以下信息:
09-13-2016 07:47:49 ERROR o.h.t.h.SchemaUpdate [https-jsse-nio-443-exec-6] HHH000388: Unsuccessful: create table users (id bigint not null auto_increment, createdOn DATETIME DEFAULT CURRENT_TIMESTAMP, token varchar(33) not null unique, updatedOn DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, userName varchar(65) not null unique, primary key (id))09-13-2016 07:47:49 ERROR o.h.t.h.SchemaUpdate [https-jsse-nio-443-exec-6] Invalid default value for 'createdOn'
查找原因,发现是由于以下导致的:
createdOn DATETIME DEFAULT CURRENT_TIMESTAMP
updatedOn DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE
在http://www.mysqltutorial.org/MySQL-timestamp.aspx中有句话:
Note that since mysql 5.6.5, the DATETIME data type also has automatic initialization and automatic update feature. In addition, the DEFAULT_CURRENT_TIMESTAMP and ON UPDATE CURRENT TIMESTAMP attributes can be applied to multiple columns, not just 1 column in the previous versions.
即对于5.6.5之前的MySQL版本,不支持多条同时使用 DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT TIMESTAMP特性,使用mysql -v查了下我现在使用的mysql版本为5.5.49,即不支持多条同时使用。因此将mysql更新至5.6.31,问题解决。