How to run db:migrate for test database in Rails 5?
Asked Answered
C

1

9

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?

Compagnie answered 13/9, 2016 at 18:48 Comment(0)
C
11

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

Compagnie answered 13/9, 2016 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.