Why there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause?
CREATE TABLE `foo` (
`ProductID` INT(10) UNSIGNED NOT NULL,
`AddedDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`UpdatedDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=INNODB;
The error that results:
Error Code : 1293
Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
Such as:
This limitation, which was only due to historical, code legacy reasons, has been lifted in recent versions of MySQL:
http://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-5.html
Well a fix for you could be to put it on the UpdatedDate field and have a trigger that updates the AddedDate field with the UpdatedDate value only if AddedDate is null.
Try this:
Combining various answers :
In MySQL 5.5,
DEFAULT CURRENT_TIMESTAMP
andON UPDATE CURRENT_TIMESTAMP
cannot be added onDATETIME
but only onTIMESTAMP
.Rules:
1) at most one
TIMESTAMP
column per table could be automatically (or manually[My addition]) initialized or updated to the current date and time. (MySQL Docs).So only one
TIMESTAMP
can haveCURRENT_TIMESTAMP
inDEFAULT
orON UPDATE
clause2) The first
NOT NULL
TIMESTAMP
column without an explicitDEFAULT
value likecreated_date timestamp default '0000-00-00 00:00:00'
will be implicitly given aDEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
and hence subsequentTIMESTAMP
columns cannot be givenCURRENT_TIMESTAMP
onDEFAULT
orON UPDATE
clauseOther option (But
updated_date
is the first column):This is the limitation in MYSQL 5.5 version. You need to update the version to 5.6.
I was getting this error in adding a table in MYSQL
table looks something like this.
After some time of reading about changes in different MYSQL versions and some of the googling. I found out that there was some changes that were made in MYSQL version 5.6 over version 5.5.
This article will help you to resolve the issue. http://www.oyewiki.com/MYSQL/Incorrect-table-definition-there-can-be-only-one-timestamp-column