8

I created a new rails 5 app with postgresql db and modified the database.yml file. I successfully created both development and test databases, but when running migrations only development db is updated and test db remains intact.

Here's the list of commands i used:

rails db:create                     # Created both development and test
rails db:migrate                    # Migrated only to development
rails db:migrate RAILS_ENV=test     # Does nothing (no error output)
rake db:migrate RAILS_ENV=test      # Same result as above

My database.yml file:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: myapp_development
  username: myapp_admin
  password:
  host: localhost
  port: 5432

test:
  <<: *default
  database: myapp_test
  username: myapp_admin
  password:
  host: localhost
  port: 5432

I also tried adding ActiveRecord::Migration.maintain_test_schema! to test_helper.rb but that didn't work either.

Any suggestions?

1 Answer 1

10

I got it to work by removing host: localhost from database.yml. Now rails db:migrate RAILS_ENV=test works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.