2011-06-14 16 views
5

我安裝設計,傾斜,然後實現後,我想補充:確定。如何在初始create_table耙後添加列來設計?

我可以返回到相同的初始遷移,只是取消註釋掉我想要的幫助程序,然後耙db:再次遷移?

我試過了,它似乎沒有工作。但我還沒有看到如何創建後續遷移的例子。

謝謝!

這是我的嘗試:

1 class AddConfirmableToUsers < ActiveRecord::Migration 
    2 def self.up 
    3  change_table :users do |t| 
    4  t.confirmable 
    5  end 
    6  add_index :users, :confirmation_token, :unique => true 
    7 end 
    8  
    9 def self.down 
10  remove_column :users, :confirmation_token 
11 end 
12 
13 end 

回答

4

您可以自行添加適當的列像這樣:

class AddConfirmableToUsers < ActiveRecord::Migration 
    def self.up 
    change_table :users do |t| 
     t.string :confirmation_token 
     t.datetime :confirmed_at 
     t.datetime :confirmation_sent_at 
    end 

    add_index :users, :confirmation_token, :unique => true 
    end 

    def self.down 
    change_table :users do |t| 
     t.remove :confirmation_token, :confirmed_at, :confirmation_sent_at 
    end 

    remove_index :users, :confirmation_token 
    end 
end 
+0

好吧,我不完全知道如何做到這一點,但是這是我正在尋找我認爲...我使用了上面的助手,應該這樣做嗎? – Angela 2011-06-15 14:25:03

+0

我會認爲使用助手會工作,但我從來沒有真正嘗試過。 – dpb 2011-06-15 21:29:01

0

你的遷移應該工作。您是否檢查了User型號以確保:confirmable已啓用?它被默認註釋掉了。

如果你不介意丟失你的數據,你可以做

> rake db:drop 

否則,您可以編輯初始遷移,並做了回滾。

# get the current migration version 
> rake db:version 
> Current version: ****************41 
> rake db:rollback ****************40 

進行更改

> rake db:migrate 
相關問題