Why do rails use datetime instead of timestamp for created_at?

Asked 2 years ago, Updated 2 years ago, 102 views

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

The datetime type is close to storing the time in a string on a DB without a time zone, and unless you have information about the time zone in which the AP (Rails) server that was running that data would not be able to handle it correctly.

If you want to save the time in the database, I think it would be better to use the timestamp type, but Rails does not have that design.

Question

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

ruby-on-rails mysql rails-activerecord

2022-09-30 20:18

1 Answers

I am sorry that I do not know the specifications of rails, but I personally think the datetime type is appropriate to record the date and time in MySQL.

Tried to verify the difference between MySQL DATETIME and TIMESTAMP types - Qiita

The reason is that, as mentioned in this article, the timestamp type will potentially include the so-called 2038 problem.
There is a possibility that future version upgrades will help, but if you try to incorporate them into the system, they may be considered a certain risk.


2022-09-30 20:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.