gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 06:37:15 26 4
gpt4 key购买 nike

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

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

关于ruby-on-rails - ruby on rails 在特定列名后添加一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15481733/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com