Skip to content

Fix test error "PG::UndefinedTable: ERROR: relation "membership_number_seq" does not exist"

Ashley Engelund edited this page May 20, 2019 · 4 revisions

The full error output looks like this:

Failure/Error: self.class.connection.execute("SELECT nextval('membership_number_seq')").getvalue(0,0).to_s
     
     ActiveRecord::StatementInvalid:
       PG::UndefinedTable: ERROR:  relation "membership_number_seq" does not exist
       LINE 1: SELECT nextval('membership_number_seq')

This can happen if the database is not being loaded from db/structure.sql

To fix:

Ensure that both your development and test environments are dumping and loading structure.sql instead of using schema.rb. You do that by setting config.active_record.schema_format = :sql in your environment config files:

  • config/environments/development.rb
  • config/environments/test.rb

The default for config.active_record.schema_format is :ruby which will use schema.db for db dump and db load.

Details: UML activity diagram of what happens during db:test:prepare

Here's a detailed UML activity diagram (flowchart) that shows what happens during db:test:prepare. This diagram starts with the SHF task db_prep which eventually calls db:test:prepare

Clone this wiki locally