Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Join table

Hi everyone, I stucked with the community app, when I run user.forums << Forum.find_by(name: "Ruby") I get the error below:

user.forums << Forum.find_by(name: "Ruby") Forum Load (0.1ms) SELECT "forums".* FROM "forums" WHERE "forums"."name" = ? LIMIT ? [["name", "Ruby"], ["LIMIT", 1]] (0.1ms) begin transaction (0.0ms) rollback transaction Traceback (most recent call last): 16: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/relation/predicate_builder.rb:100:in each' 15: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/relation/predicate_builder.rb:124:inblock in create_binds_for_hash' 14: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/relation/predicate_builder.rb:165:in build_bind_param' 13: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/table_metadata.rb:34:intype' 12: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/model_schema.rb:372:in type_for_attribute' 11: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/model_schema.rb:353:inattribute_types' 10: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/model_schema.rb:452:in load_schema' 9: from /home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:inmon_synchronize' 8: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/model_schema.rb:455:in block in load_schema' 7: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/attribute_decorators.rb:28:inload_schema!' 6: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/attributes.rb:233:in load_schema!' 5: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/model_schema.rb:462:inload_schema!' 4: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/schema_cache.rb:62:in columns_hash' 3: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/schema_cache.rb:56:incolumns' 2: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:304:in columns' 1: from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:429:intable_structure' ActiveRecord::StatementInvalid (Could not find table 'forums_users')

1 Answer

I got the answer:

After creating the join table migration we need to run bin/rails db:migrate