Imdad Imdad - 17 days ago 5
MySQL Question

Error in setting the default value to CURRENT_TIMESTAMP

I am having problem while altering a table. I need a column with data type DATETIME to take default value as current date/time and on update also it should automatically update it's value to current date/time. I am writing the following SQL

ALTER TABLE `groups`
CHANGE COLUMN `modified` `modified` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP


I am getting the following error message.

Error Code: 1067. Invalid default value for 'modified'


The MySQL version I'm using is 5.5.49 on a Ubuntu 14.04.1 system.

Please let me know how this can be fixed.

Jan Jan
Answer

Prior to MySQL 5.6.5, you can only use the CURRENT_TIMESTAMP default value for columns of type TIMESTAMP. See http://stackoverflow.com/a/9005872/1293303