ruby on rails 在特定列名后添加一列 [英] ruby on rails add a column after a specific column name

查看:22
本文介绍了ruby on rails 在特定列名后添加一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried to add a column to a table after a specific column in the table. Here is what I did:

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

这是我的迁移文件的样子:

Here is what my migration file looks like:

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

我不认为命令进行得很好.我在上面的文件中看到一个=".我不认为它应该在那里.有人能告诉我我是否遗漏了什么吗?

I dont think the command went well. I see an '=' in the above file. I do not think it should be there. Can someone tell me if I missed anything?

如果是这样,我该如何撤消上述操作?

If so , how do I undo the above?

推荐答案

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

I doubt it allowed you to actually rake db:migrate this migration, so you shouldn't have to roll back. Just remove the bottom three add_columns and replace the top one with

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

迁移应该没问题.为了将来参考,您输入的命令应如下所示:

and it should be fine to migrate. For future reference, here's what that command you entered should look like:

rails generate migration add_reaction_id_to_patient_allergies reaction_id:integer

integer 之前的空格让生成器认为这是一个新列.遗憾的是,您也不能在命令行上使用 Ruby 语法 (a => b).

The space before integer made the generator think it was a new column. Sadly you can't use Ruby syntax (a => b) on the command line either.

这篇关于ruby on rails 在特定列名后添加一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆