Rake db:migrate无法与pg Gem一起使用。如何解决错误?

时间:2018-12-14 16:55:20

标签: ruby-on-rails postgresql ruby-on-rails-5

我正在使用Rails 5 + pg Gem + AWS Cloud9。尝试“耙db:setup”时,出现以下错误:

$ rake db:setup
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:

  * development - set it to false
  * test - set it to false (unless you use a tool that preloads your test environment)
  * production - set it to true

rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

我正在使用以下教程:https://medium.com/@noordean/setting-up-postgresql-with-rails-application-357fe5e9c28

这是我的文件:

/app/config/database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  username: <%= ENV['POSTGRES_USER'] %>
  password: <%= ENV['POSTGRES_PASSWORD'] %>
  pool: 5
  timeout: 5000
  host: <%= ENV['POSTGRES_HOST'] %>
development:
  <<: *default
  database: <%= ENV['POSTGRES_DB'] %>
test:
  <<: *default
  database: <%= ENV['POSTGRES_TEST_DB'] %>
production:
  <<: *default
  database: <%= ENV['POSTGRES_DB'] %>

/app/.env

POSTGRES_USER='user'
POSTGRES_PASSWORD='user'
POSTGRES_HOST='localhost'
POSTGRES_DB='your_database_name'
POSTGRES_TEST_DB='your_database_name_test'

1 个答案:

答案 0 :(得分:0)

确定您的计算机上正在运行postrges,请尝试在终端上与psql连接

psql -U user -d your_database_name