0

why do i get invalid default value error for the variable "last_updated"? note i am getting this error while i run the following code in MySQL console in phpmyadmin

 CREATE TABLE IF NOT EXISTS `articles` (
   `article_id` int(10) NOT NULL AUTO_INCREMENT,
    `content_id` int(10) NOT NULL,
    `article_body` text NOT NULL,
    `last_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
     PRIMARY KEY (`article_id`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=532 ;
  • Possible duplicate of [Invalid default value for 'dateAdded'](http://stackoverflow.com/questions/9005766/invalid-default-value-for-dateadded) – Nicolas Feb 21 '16 at 13:09

2 Answers2

0

You need to change the last_updated column's data type to timestamp rather than datetime. This will allow the use of CURRENT_TIMESTAMP as a default value.

As it happens, these two data types are represented in the same format YYYY-MM-DD HH:MM:SS. So if/when you use the data, you shouldn't run into any troubles.

Adam Copley
  • 1,495
  • 1
  • 13
  • 31
0

Check your MySQL server version, CURRENT_TIMESTAMP is allowed since version 5.6.5 as DEFAULT for DATETIME type, otherwise you should use either TIMESTAMP type or maintain it outside.

mitkosoft
  • 5,262
  • 1
  • 13
  • 31