Windows上的PostgreSQL Ruby on Rails 5 - fe_sendauth:未提供密码

时间:2017-06-09 10:47:03

标签: ruby-on-rails postgresql heroku

我正在关注this guide与Postgres建立一个rails项目。

到目前为止,我已经安装了postgress和Heroku工具带,并完成了以下工作:

  1. 使用我的heroku凭据登录
  2. 使用postgres rails new myapp --database=postgresq
  3. 创建了一个rails项目
  4. 默认的database.yml文件如下所示:

    default: &default
      adapter: postgresql
      encoding: unicode
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
    
    development:
      <<: *default
      database: myapp_development
    
    test:
      <<: *default
      database: myapp_test
    
    production:
      <<: *default
      database: myapp_production
      username: myapp
      password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
    
  5. 为主页rails g controller welcome

  6. 创建了控制器
  7. 创建了index.html.erb并添加了路由。 root 'welcome#index'

  8. 然后当我运行服务器时,转到localhost:3000并收到以下错误 PG::ConnectionBad (fe_sendauth: no password supplied):

    是database.yml文件的问题还是postgres的安装和设置?

3 个答案:

答案 0 :(得分:1)

在config / database.yml中,默认情况下:&default,添加:

 host: localhost
 username: postgres
 password: (the password you created during postgresql installation goes here)
 port: 5432

然后在终结器中运行rake db:create:all(如果在这里遇到相同的问题,请不要担心),然后运行rake db:migrate,重新启动Rails服务器,您的应用现在应该可以工作了。

P.S。我注意到这个问题是一年多以前提出的,那时您已经找到了解决方案。但是我将这种解决方案放在这里,因为两天前我遇到了这个问题,因此可能遇到同样的问题的人,这花了我一些时间才能找出对我有用的解决方案。

答案 1 :(得分:0)

想通了。我只需要打开pgAdmin并使用我在安装过程中创建的密码登录。

答案 2 :(得分:0)

将用户名和密码添加为默认值

default: &default
      adapter: postgresql
      encoding: unicode
      # For details on connection pooling, see Rails configuration guide
      # https://guides.rubyonrails.org/configuring.html#database-pooling
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      username: postgres
      password: postgres