ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
你看看,问题又来了,这样彻底晕了,同样的建表语句,只是字段顺序变掉了,就错了?
莫非这是Mysql 的 BUG? 去Mysql Buglist中去查查看,结果没有类似bug。
目前能想到的就是仔细去看看官方文档对于CURRENT_TIMESTAMP的描述
1
2
3
* Mysql 5.1 *
One TIMESTAMP column ina table can have the current timestamp asthe default valuefor initializing the column, asthe auto-update value, or both. It is not possible to have the current timestamp be the default valueforone column andthe auto-update valuefor another column.
看的仔细的同学就会发现,current timestamp as the default value for initializing the column,意思就是Mysql 会初始化第一个TIMESTAMP字段的default值为‘current timestamp’。一个表里面多个TIMESTAMP column 只能拥有一个‘current timestamp’值。
Previously, at most one TIMESTAMP column per table could be automatically initialized or updated tothe current dateandtime. 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.
测试:
1
2
3
4
5
6
7
8
9
10
11
12
13
* Mysql 5.6*
dbadmin:test> create table lc_test_1(
`update_time` timestamp NOTNULL,
`upload_time` timestamp NOTNULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '上传时间'