Ruby on Rails的一个特定的列名后添加一列(ruby on rails add a col

2019-07-21 21:39发布

我试图在表中的特定列之后将列添加到表中。 下面是我做的:

rails generate migration add_reaction_id_to_patient_allergies reaction_id: integer :after => 'patient_id'

这里是我的移民文件的样子:

class AddReactionIdToPatientAllergies < ActiveRecord::Migration
  def change
    add_column :patient_allergies, :reaction_id, :string
    add_column :patient_allergies, :integer, :string
    add_column :patient_allergies, :, :after
    add_column :patient_allergies, :=, :string
  end
end

我不认为命令进行得很顺利。 我在上述文件中看到一个“=”。 我不认为它应该在那里。 谁能告诉我,如果我错过了什么?

如果是这样,我怎么撤消以上?

Answer 1:

我怀疑它让你真正rake db:migrate此迁移,所以你不应该有回滚。 只需卸下底部的三个add_column S和更换最上面的一个与

add_column :patient_allergies, :reaction_id, :integer, after: :patient_id

它应该是罚款迁移。 对于未来的参考,这就是你输入的命令应该是什么样子:

rails generate migration add_reaction_id_to_patient_allergies reaction_id:integer

之前的空间integer做出的发电机认为这是一个新的列。 不幸的是,不能使用的Ruby语法( a => b在命令行上)任一。



文章来源: ruby on rails add a column after a specific column name