Add timestamps to an existing table

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

    class AddTimestampsToUser < ActiveRecord::Migration
      def change
        change_table :users do |t|
          t.timestamps
        end
      end
    end
    

    Available transformations are

    change_table :table do |t|
      t.column
      t.index
      t.timestamps
      t.change
      t.change_default
      t.rename
      t.references
      t.belongs_to
      t.string
      t.text
      t.integer
      t.float
      t.decimal
      t.datetime
      t.timestamp
      t.time
      t.date
      t.binary
      t.boolean
      t.remove
      t.remove_references
      t.remove_belongs_to
      t.remove_index
      t.remove_timestamps
    end
    

    http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html

提交回复
热议问题