ruby on rails在特定列名后添加一列

我尝试在表中的特定列之后向表中添加一列。 这是我做的:

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 

我不认为命令进展顺利。 我在上面的文件中看到了’=’。 我不认为应该在那里。 有人能告诉我,如果我错过了什么?

如果是这样,我该如何撤消上述内容?

我怀疑它是否允许您实际使用rake db:migrate此迁移,因此您不必回滚。 只需删除底部的三个add_column并将顶部替换为

 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 )。