I have two columns created_at and updated_at in same table. Both the columns have data type as datetime. Now when I am trying to modify the column data types as follows -
alter table nodestatics modify column updated_at datetime default current_timestamp;
alter table nodestatics modify column created_at datetime default current_timestamp;
It is showing the following error
Error Code : 1067 Invalid default value for 'updated_at' (0 ms taken)
Error Code : 1067 Invalid default value for 'created_at' (0 ms taken)
My mysql version is 5.5.41-0ubuntu0.14.04.1 (Ubuntu)
It is hard to reference documentation in a comment:
As of MySQL 5.6.5,
TIMESTAMP
andDATETIME
columns can be automatically initializated and updated to the current date and time (that is, the current timestamp). Before 5.6.5, this is true only forTIMESTAMP
, and for at most oneTIMESTAMP
column per table.
Either upgrade to 5.6.5. Or use TIMESTAMP
instead of DATETIME
.