我使用 postgresql db 创建了一个新的 rails 5 应用程序并修改了 database.yml 文件。我成功创建了开发和测试数据库,但是在运行迁移时,仅更新开发数据库,测试数据库保持不变。
这是我使用的命令列表:
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
我的 database.yml 文件:
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
我也尝试将
ActiveRecord::Migration.maintain_test_schema!
添加到 test_helper.rb
但这也不起作用。有什么建议么?
最佳答案
我通过从 database.yml 中删除 host: localhost
使其工作。现在 rails db:migrate RAILS_ENV=test
工作正常。
关于ruby-on-rails-5 - 如何运行数据库 :migrate for test database in Rails 5?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39477047/