Add timestamps to an existing table

前端 未结 21 1149
予麋鹿
予麋鹿 2020-12-12 14:34

I need to add timestamps (created_at & updated_at) to an existing table. I tried the following code but it didn\'t work.

class          


        
21条回答
  •  不知归路
    2020-12-12 15:26

    I personally used the following, and it updated all previous records with the current time/date:

    add_column :, :created_at, :datetime, default: Time.zone.now, null: false
    add_column :
    , :updated_at, :datetime, default: Time.zone.now, null: false

    提交回复
    热议问题