In my database migration file I inserted the line:
t.timestamps
Two columns, as I expected, were created: "updated_at" and "created_at". However, their type is "datetime" and not "timestamp".
I am using MySQL and the "timestamp" type, as I understand, is designed exactly for such cases, as it uses less space and is independent of timezone.
So, is there any reason, why Rails 3 uses "datetime" and not "timestamp"? Should I try to fix that? If yes, is there any way to do this besides not using "t.timestamps" and defining "updated_at" and "created_at" columns separately every time for each new table?
From memory, the mysql timestamp
column type behaves similar to updated_at
in that it is updated with the current time whenever the record is updated.
While this is useful for the updated_at
column, this is not the desired behaviour for created_at
.
In addition, Rails handles the timezone as specified in your app's settings (should would normally be set to UTC), so using mysql's time may be inconsistent with other datetime records.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With