rails c does not start and a lot of line errors appear

problem

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.

Conclusion

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.

mistake

(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.

  1. Order of description You are using room_users in through before writing has_many: room_users.
  2. Model name I have an association with myself in the room model.

Revised

(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

Why are associations related to rails s and rails c?

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

rails c does not start and a lot of line errors appear
Many error lines ... Rails server does not start 2. "Autodetect': Could not find a JavaScript runtime."
Localhost3000 does not start up in Docker / Rails development.
[Rails] Volume that displays favorites and a list of favorites
When the server does not start with rails s
Terminal does not start
Port C code with a lot of typecasts to Swift
A trick when you want to insert a lot of line breaks and tabs when substituting a character string
Creating a mixed conditional expression of Rails if statement and unless