Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do the created_at and updated_at columns come from?

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 internal rely on them?

like image 457
kdt Avatar asked Jan 18 '11 10:01

kdt


People also ask

What is Created_at and Updated_at?

The timestamp when the record was first created in the database. updated_at. The timestamp of the most recent change to any of the data stored in the table.

What is created at in mysql?

The CREATE TABLE statement is used to create a new table in a database.


1 Answers

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
like image 52
John Topley Avatar answered Oct 13 '22 00:10

John Topley