ruby-on-rails – Why does rails use datetime instead of timestamp for created_at etc?

Question: Question:

Rails ActiveRecord creates a datetime type on the DB for the created_at and updated_at columns introduced by t.timestamps in migration, at least in MySQL.

The datetime type is similar to storing the time as a character string on the DB without a time zone, and information on which time zone the AP (Rails) server on which the data was running was running is available. Unless you do, the data will not be handled correctly.

If you want to store the time in a database, so I think it would be better to use the timestamp type, but Rails doesn't have that design.

question

  • Why does rails use datetime instead of timestamp for created_at and updated_at ?

Answer: Answer:

I'm sorry I don't know the rails specifications, but I personally think that the datetime type is suitable for recording the date and time with MySQL.

I tried to verify the difference between MySQL DATETIME type and TIMESTAMP type –Qiita

The reason is that, as you can see in this article, the timestamp type potentially involves the so-called Year 2038 problem.
There is a possibility that it will be dealt with in future version upgrades, but if you try to incorporate it into the system, it may be considered a certain risk.

Scroll to Top