在初始create_table rake之后如何添加列设计? [英] How do I add columns to devise after the initial create_table rake?
本文介绍了在初始create_table rake之后如何添加列设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我安装了Devise,然后,然后意识到,我想添加:confirmable。
I installed Devise, raked, and then realized afterwards, that I want to add :confirmable.
我可以回到相同的初始迁移,只是取消注释我想要的帮手,然后耙db:再次迁移?
Can I go back to the same initial migration and just uncomment out the helper that I want and then rake db:migrate again?
我尝试了,似乎没有工作。但是我没有看到如何创建一个后续迁移的例子。
I tried it and it didn't seem to work. But I haven't seen an example of how to create a follow-on migration.
谢谢!
这是我试过的:
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
推荐答案
您可以自己添加适当的列: p>
You can add the proper columns yourself like so:
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
这篇关于在初始create_table rake之后如何添加列设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文