Chris Farrugia
Chris Farrugia

Reputation: 1046

Invalid default value on a timestamp field? What's wrong?

I am running mysql Ver 14.14 Distrib 5.5.40, for debian-linux-gnu (i686) using readline 6.2

When I try to do the query below, I get an error saying, "Invalid default value for 'created_at'"

I read somewhere this could be due to the MySQL Mode but there is nothing set in my.ini for the mode.

The query is:

CREATE TABLE `rets_feeds` (
`id` tinyint(4) NOT NULL AUTO_INCREMENT,
`board` varchar(20) DEFAULT NULL COMMENT 'The board providing the feed.',
`feedurl` varchar(255) DEFAULT NULL COMMENT 'The URL to log into the feed.',
`username` varchar(255) DEFAULT NULL COMMENT 'Feed Username',
`password` varchar(255) DEFAULT NULL COMMENT 'Feed Password',
`active` char(1) DEFAULT '1',
`last_query_at` datetime DEFAULT NULL COMMENT 'The last time the RETS feed queried the server and returned results.',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Record Creation Date',
`updated_at` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Record Update Date',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Upvotes: 0

Views: 2215

Answers (1)

Marc B
Marc B

Reputation: 360702

As per the docs: http://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html

One TIMESTAMP column in a table can have the current timestamp as the default value for initializing the column, as the auto-update value, or both. It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column.

Upvotes: 3

Related Questions