:datetime and :timestamp in a migration file seems like the same in MySQL and Sqlite3, and they both map to datetime in the database side, except I can’t find that in a formal documentation.
Also, what about when if our Rails project may use other DBMS, then should we use :datetime or :timestamp when we script/generate (or rails generate) our Model or Scaffold?
I would recommend using the
:datetime, because so it’s clear what to use. I believe rails is usingDATETIMEfor both in the DB is because of the Problem that the datetimes representable with the unix timestamp or the MySQLTIMESTAMPfield. Since timestamp is by default a 32bit Integer (see Wikipedia:Timestamp) it can only represent dates between1901-12-13(or1970-01-01if no negative values are allowed like in MySQL) and2038-01-19. After or before that it will overflow. This is the year 2038 problem.So to make it clear to everybody I would name it
:datetimein the migration.