【问题标题】:Rake db:migrate not working with pg Gem. How to fix error?Rake db:migrate 不适用于 pg Gem。如何修复错误?
【发布时间】:2018-12-14 16:55:19
【问题描述】:

我正在使用 Rails 5 + pg Gem + AWS Cloud9。尝试“rake 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'

【问题讨论】:

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


    【解决方案1】:

    你确定你的机器上正在运行 postrges,尝试在你的终端上连接 psql

    psql -U user -d your_database_name

    【讨论】:

    • 我收到以下错误:psql:无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受 Unix 域套接字上的连接“/var/run/postgresql/.s.PGSQL .5432"?
    • 这就是答案,您需要在笔记本电脑上安装并运行 Postgres
    猜你喜欢
    • 2015-04-23
    • 1970-01-01
    • 2017-04-16
    • 2018-10-06
    • 2013-06-03
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多