Can't run rspec tests: ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR: relation "thing"

ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR: relation "thing"

In some cases, I have run into an issue when I try to run rspec tests, it says

Migrations are pending. To resolve, run: rails db:migrate RAILS_ENV=test

But then when I run that, I see this error:

ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR: relation "thing"

To resolve this, run this:

bundle exec rake db:reset RAILS_ENV=test

That will reset the test database. Now you can proceed with running tests normally.

Last updated