Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActiveRecord抱怨列(供参考)不存在,所以我手动创建它,它抱怨它确实存在_Ruby On Rails_Ruby_Activerecord - Fatal编程技术网

Ruby on rails ActiveRecord抱怨列(供参考)不存在,所以我手动创建它,它抱怨它确实存在

Ruby on rails ActiveRecord抱怨列(供参考)不存在,所以我手动创建它,它抱怨它确实存在,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,假设进行以下迁移: class AddSectionReferences < ActiveRecord::Migration def change add_reference :sections, :sections, index: true, foreign_key: true, on_delete: :nullify add_reference :sections, :parent end end 因此,如果我加上: add_column :section

假设进行以下迁移:

class AddSectionReferences < ActiveRecord::Migration
  def change

    add_reference :sections, :sections, index: true, foreign_key: true, on_delete: :nullify 
    add_reference :sections, :parent
  end
end
因此,如果我加上:

add_column :sections, :sections_id, :integer
在提交之前,它会投诉:

ActiveRecord::StatementInvalid: PG::DuplicateColumn: ERROR:  column "sections_id" of relation "sections" already exists
: ALTER TABLE "sections" ADD "sections_id" integer
发生了什么,当我试图为has\u many创建复数列时,为什么要在第一个错误中查找section\u id列

当我试图为a创建一个复数列时,有多少

你是从错误的方向来的。您如何想象此列包含多个/无限ID?这不是rails所期望的

在has\u many关系中,外键列位于“属于”一侧。当然,列名应该是单数。因为它只能保存一个id

t.references :section

OP应该紧随其后this@Mark:你认为是这样吗?@马克:导游-那是肯定的。只是你的链接直接指向has_many:through部分。我还不确定。啊,我和你在一起是的,我链接到了错误的部分,我的坏!但无论如何,读这本书可能不会伤害他:
t.references :section