0
假设为以下迁移: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
它抱怨:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "section_id" referenced in foreign key constraint does not exist
: ALTER TABLE "sections" ADD CONSTRAINT "fk_rails_810c69e885"
所以如果我添加:
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
这是怎么回事,为什么它在第一个错误寻找section_id
列,当我试图创建(为的has_many)复数列?
http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association OP应遵循此 – Mark
@马克:你认为是这样吗? –
从他的问题看起,他还没有看到它:( – Mark