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
複数列(has_manyの場合)を作成しようとすると、最初のエラーでsection_id
列を探しているのはなぜですか?
http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association OPはこの – Mark
@マークに従ってください:あなたはそれが事実だと思いますか? –
彼の質問の外見から彼はまだそれを読んでいない:( – Mark