maandag 24 september 2007

mysql with create_at and modified_at timestamps

Creating a table with two timestamps, one default and one on update, creates an error in mysql.
using default 0, solves this problem, but you need to insert a 0 to get the desired result of a created at timestamp.


create table example(
id int not null auto_increment,
code varchar(250),
created_at TIMESTAMP default 0,
modified_at TIMESTAMP on update current_timestamp,
primary key(id)
) engine innodb;


Rails has some timestamping conventions/methods of its own, but i think this kind of intelligence should reside within the database, not in a web framework.

Geen opmerkingen: