2

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.

Imdad
  • 5,942
  • 4
  • 33
  • 53

2 Answers2

1

Most probably this is because you already have another column with CURRENT_TIMESTAMP as default.

In MySQL versions prior to 5.6 this is a problem:

Why there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT clause?

Community
  • 1
  • 1
Matijs
  • 2,533
  • 20
  • 24
1

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

Community
  • 1
  • 1
Jan
  • 1,040
  • 14
  • 29