Add timestamps to an existing table

前端 未结 21 1114
予麋鹿
予麋鹿 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:06

    add_timestamps(table_name, options = {}) public

    Adds timestamps (created_at and updated_at) columns to table_name. Additional options (like null: false) are forwarded to #add_column.

    class AddTimestampsToUsers < ActiveRecord::Migration
      def change
        add_timestamps(:users, null: false)
      end
    end
    

提交回复
热议问题