移行

0

を実行している上、テーブルのエラーに参加し、私は、問題は、私は、マイグレーションを実行しようとすると、マイグレーションでテーブルcomfort_factor_sub_categoriesを作成するので、私はエラーERROR: relation "comfort_factor_sub_categories" does not existを取得している複数の移行を追加したレールに2つのモデル5.1移行

class Category < ActiveRecord::Base 
    has_and_belongs_to_many :sub_categories, join_table: "categories_join_table" 
end 

class SubCategory < ActiveRecord::Base 
    has_and_belongs_to_many :categories, join_table: "categories_join_table" 
end 

を持っています後の移行で実行されます。これをどうすれば処理できますか? 注:join_tableの名前を変更することはできません。例としては長い名前があります。

+0

は、あなたがそれはそれについてのガイドで提案されているものとは別の何かを行っているレールに参照することができますか? http://guides.rubyonrails.org/association_basics.html#creating-join-tables-for-has-and-belongs-to-many-associationsあなたのマイグレーションで行ったことのサンプルを共有できますか? – mabe02

答えて

0

問題を正しく理解していれば、いくつかの移行が追加されており、関係が見つからないため実行できません。その場合

、あなたはduplicate the classes in migrationsべき:

class CreateCategories < ActiveRecord::Migration[5.1] 
    class Category < ActiveRecord::Base 
    # without declaring the relationship with the table which does not exist yet 
    end 

    def up 
    create_table :categories do |t| 
     # t.something 
    end 
    end 
    def down 
    drop_table :categories 
    end 
end 

その後、SubCategoryのために同じことを行う必要があります。適切なjoin_tableを作成するための

、あなたはofficial documentation