Search code examples
ruby-on-rails-3ruby-on-rails-4activerecordrails-migrations

How to add created_at and updated_at when creating a table with a Rails migration


Rails g migration CreateFoo

This does not add created_at and update_at to the migration. Is there a way to generate a migration and add timestamps as a param?

Rails g migration CreateFoo timestamps didn't work.


Solution

  • Seems like those only get generated automatically with models.

    Otherwise you can add it manually in a create with t.timestamps or with add_timestamps :foo to change an existing table.