UndefinedTable: ERROR: relation "web_hook_event_types" when trying to run rspec test

On my dev environment, on Mac, after running this:
bundle exec rspec spec/components/new_post_manager_spec.rb
which results in an error

bundler: failed to load command: rspec (/usr/local/bin/rspec)
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "web_hook_event_types" does not exist
LINE 5:                WHERE a.attrelid = '"web_hook_event_types"'::...
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"web_hook_event_types"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in exec_no_cache'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
  /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `exec_no_cache'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:584:in `execute_and_clear'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in `exec_query'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:733:in `column_definitions'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:197:in `columns'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/schema_cache.rb:43:in `columns'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/attributes.rb:93:in `columns'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/attributes.rb:98:in `columns_hash'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/query_methods.rb:969:in `block in create_binds'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/query_methods.rb:967:in `each'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/query_methods.rb:967:in `partition'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/query_methods.rb:967:in `create_binds'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/query_methods.rb:954:in `build_where'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/query_methods.rb:584:in `where!'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/query_methods.rb:574:in `where'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/finder_methods.rb:84:in `find_by'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/querying.rb:7:in `find_by'
  /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/core.rb:164:in `find_by'
  /Users/pmusaraj/Projects/discourse/spec/fabricators/web_hook_fabricator.rb:9:in `block in <top (required)>'
  /usr/local/lib/ruby/gems/2.3.0/gems/fabrication-2.9.8/lib/fabrication/schematic/evaluator.rb:5:in `instance_eval'
  /usr/local/lib/ruby/gems/2.3.0/gems/fabrication-2.9.8/lib/fabrication/schematic/evaluator.rb:5:in `process'
  /usr/local/lib/ruby/gems/2.3.0/gems/fabrication-2.9.8/lib/fabrication/schematic/definition.rb:18:in `process_block'
  /usr/local/lib/ruby/gems/2.3.0/gems/fabrication-2.9.8/lib/fabrication/schematic/definition.rb:14:in `initialize'
  /usr/local/lib/ruby/gems/2.3.0/gems/fabrication-2.9.8/lib/fabrication/schematic/manager.rb:69:in `new'
  /usr/local/lib/ruby/gems/2.3.0/gems/fabrication-2.9.8/lib/fabrication/schematic/manager.rb:69:in `schematic_for'
  /usr/local/lib/ruby/gems/2.3.0/gems/fabrication-2.9.8/lib/fabrication/schematic/manager.rb:49:in `store'
  /usr/local/lib/ruby/gems/2.3.0/gems/fabrication-2.9.8/lib/fabrication/schematic/manager.rb:27:in `register'
  /usr/local/lib/ruby/gems/2.3.0/gems/fabrication-2.9.8/lib/fabrication.rb:58:in `Fabricator'
  /Users/pmusaraj/Projects/discourse/spec/fabricators/web_hook_fabricator.rb:1:in `<top (required)>'
  /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
  /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `block in require'
  /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
  /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
  /Users/pmusaraj/Projects/discourse/spec/rails_helper.rb:32:in `block (2 levels) in <top (required)>'
  /Users/pmusaraj/Projects/discourse/spec/rails_helper.rb:32:in `each'
  /Users/pmusaraj/Projects/discourse/spec/rails_helper.rb:32:in `block in <top (required)>'
  /usr/local/lib/ruby/gems/2.3.0/gems/spork-1.0.0rc4/lib/spork.rb:24:in `prefork'
  /Users/pmusaraj/Projects/discourse/spec/rails_helper.rb:15:in `<top (required)>'
  /Users/pmusaraj/Projects/discourse/spec/components/new_post_manager_spec.rb:1:in `require'
  /Users/pmusaraj/Projects/discourse/spec/components/new_post_manager_spec.rb:1:in `<top (required)>'
  /usr/local/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `load'
  /usr/local/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
  /usr/local/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `each'
  /usr/local/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
  /usr/local/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in `setup'
  /usr/local/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run'
  /usr/local/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
  /usr/local/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
  /usr/local/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
  /usr/local/bin/rspec:22:in `load'
  /usr/local/bin/rspec:22:in `<top (required)>'

I also ran what is suggested here:

but that didn’t fix it.

Any ideas?

You probably have to RAILS_ENV=test rake db:migrate

Did that, it didn’t fix it.

I deleted the discourse_test database, went over steps to recreate the database from the guide to install on Mac and now it’s fixed.

1 Like