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