On_update current_timestamp in Migrations

Is there any way to set database columns to auto update a timestamp
column on update?
Can I do something like
t.column “timestamp”, :datetime, :default => :current_time, :null
=> false, :on_update => :current_timestamp

or do i need to just use custom sql like

sql = “ALTER TABLE table CHANGE timestamp timestamp TIMESTAMP ON
UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP”

exectue sql

Any help is appreciated. Thanks.

Is there any way to set database columns to auto update a timestamp
column on update?

If you simply name your column ‘updated_at’, Rails will update it
automatically when its parent record is updated.

FYI, ‘updated_at’ is a magic column name™. For some others, see

http://wiki.rubyonrails.com/rails/pages/MagicFieldNames

  • Danny

Daniel B. wrote:

Is there any way to set database columns to auto update a timestamp
column on update?

If you simply name your column ‘updated_at’, Rails will update it
automatically when its parent record is updated.

FYI, ‘updated_at’ is a magic column name™. For some others, see

Peak Obsession

  • Danny

Wow, that’s excellent. The more I learn about rails, the more I love
it. Thank you!