嘿,当我第一次开始一个rails项目时,模型用户就被设计和创建了。在所有的迁移部分之后,它成功地在postgres创建了表格“users”。 那么,在项目进行一些修改之后,我意识到在表格中缺少一个属性/新列。Ruby-on-rails中的迁移问题
所以我所做的就是从Postgres的删除表的用户,并在我的第一个迁移的Ruby类增加一个新的列:
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name
t.string :password
t.string :email
t.string :authorization_token //this is the new attribute that I insert
t.datetime :created_at
t.datetime :updated_at
t.timestamps
end
end
def self.down
drop_table :users
end
end
所以,当我再次运行分贝:迁移跳一个新的用户表将使用新属性authorization_token创建,但它不起作用,但没有错误。
(我知道我不应该删除表,还有另一种聪明的方式做到这一点)
谢谢,我做了你说的和工作:) – mateusmaso 2010-08-30 00:53:38