2012-12-05 68 views
0

我正在使用rails 3.2進行以下遷移,並且created_at/updated_at都生成了。我的印象是添加t.timestamps是造成這些列產生的原因。爲什麼遷移沒有時間戳時會創建created_at/updated_at?

class CreateContactsCountries < ActiveRecord::Migration 
    def change 
    create_table :contacts_countries do |t| 
     t.string :name, :official_name, :null => false 
     t.string :alpha_2_code, :null => false, :limit => 2 
     t.string :alpha_3_code, :null => false, :limit => 3 
    end 

    add_index :contacts_countries, :alpha_2_code 
    end 
end 
+0

你確定嗎?我使用的是Rails 3.2.8,當我刪除t.timestamps並運行遷移時,它沒有創建created_at並在字段中更新。 –

回答

0

請刪除表和監守

By default, the generated migration will include t.timestamps (which creates 
the updated_at and created_at columns that are automatically populated 
by Active Record). 

價再次檢查this

+0

感謝您的回覆。我放棄了桌子,重新進行了遷移,並且時間戳不存在。不知道第一次發生了什麼事。對我來說可能是一個疏忽 – bons