Where do the created_at and updated_at columns come from?

前端 未结 3 460
失恋的感觉
失恋的感觉 2021-01-04 01:59

All the tables in the database created by a rails application seem to have created_at and updated_at columns. What creates these? Are they optional, or does something inte

3条回答
  •  [愿得一人]
    2021-01-04 02:22

    They are created by default when you run the ActiveRecord migration for a model. ActiveRecord automatically populates/updates them when you create or update a model instance (and thus the underlying database table row) respectively.

    You can remove the columns by removing the t.timestamps line from within the model migration file.

    • Ruby on Rails Guides: Migrations

提交回复
热议问题