I tried to launch the console with rails c about after creating the intermediate table, but I got the following error
: Unknown key: :throught. Valid keys are: :class_name, :anonymous_class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type, :index_errors (ArgumentError)
rails s didn't start up either.
The association of the intermediate table was incorrect. After modifying as follows, it is solved by db: migrate: reset.
There was a room-users table as an intermediate table between the rooms table and the users table, The association was organized as follows. Since db: migrated with the table relationship being strange, it was solved by deleting and recreating the table with db: migrate: reset and performing db: migrate.
(room model)
class Room < ApplicationRecord
has_many :rooms, through: :room_users
has_many :room_users
end
(user model)
has_many :rooms, through: :room_users
has_many :room_users
There are two mistakes.
(room model)
class Room < ApplicationRecord
has_many :room_users
has_many :users, through: :room_users
end
(user model)
has_many :room_users
has_many :rooms, through: :room_users
To pass through databases and migration files when launching the console or local server. An error occurred without the migration file, and the console and local server did not start.
that's all.
Recommended Posts