cliveportman/code

Create MySQL table with two timestamps

Was creating a MySQL table with two timestamps, as so:

added TIMESTAMP NOT NULL default NOW(),
updated TIMESTAMP NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,

but was getting this error:

Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause.

For some reason, the following got round it:

added TIMESTAMP NOT NULL default ’0000-00-00 00:00:00′,
updated TIMESTAMP NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,