【发布时间】:2010-08-29 23:23:12
【问题描述】:
大家好,当我第一次开始一个 Rails 项目时,模型用户是设计和创建的。在完成所有迁移部分之后,它成功地在 postgres 上创建了表“users”。 好吧,然后在项目期间进行了一些更改后,我意识到表格中缺少一个属性/新列。
所以我所做的就是从 postgres 中删除表 users 并在我的第一个迁移 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
所以,当我再次运行 db:migrate 时,将使用新属性 :authorization_token 创建一个新的用户表,它不起作用,但没有错误。
(我知道我不应该删除表格,还有另一种聪明的方法)
【问题讨论】:
标签: ruby-on-rails postgresql rubymine