Rails 3.1使用change_table迁移添加列

mar*_*tnu 5 ruby-on-rails ruby-on-rails-3.1

我有一个profiles用一些列调用的表.

现在,我希望使用changerails 3.1中的-method 为此表添加几列.我使用以下代码创建了一个迁移:

def change
  change_table :profiles do |t|
    t.string :photo
    t.string :name
    t.references :user
  end
end
Run Code Online (Sandbox Code Playgroud)

迁移工作完美,但是当我想要回滚时,我得到了

SQLite3::SQLException: duplicate column name: photo: ALTER TABLE "profiles" ADD "photo" varchar(255)
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

sev*_*cat 5

在Rails 3.1中添加列的自动生成的迁移格式如下:

class AddColumnToTable < ActiveRecord::Migration
  def change
    add_column :table, :column, :type
  end
end
Run Code Online (Sandbox Code Playgroud)

也许尝试那种语法?