Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 641
Gerry Avatar asked Sep 13 '16 18:09

Gerry


1 Answers

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

like image 200
Gerry Avatar answered Oct 28 '22 22:10

Gerry