【问题标题】:PostgreSQL Ruby on Rails 5 on Windows - fe_sendauth: no password suppliedWindows 上的 PostgreSQL Ruby on Rails 5 - fe_sendauth:未提供密码
【发布时间】:2017-06-09 10:47:03
【问题描述】:

我正在关注this guide 用 Postgres 建立一个 Rails 项目。

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

  1. 使用我的 heroku 凭据登录
  2. 使用 postgres rails new myapp --database=postgresq 创建了一个 Rails 项目
  3. 默认的 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'] %>
    
  4. 为主页创建控制器rails g controller welcome

  5. 创建了 index.html.erb 并添加了路由。 root 'welcome#index'

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

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

【问题讨论】:

  • 好像&lt;%= ENV['MYAPP_DATABASE_PASSWORD'] %&gt; 是nil。你确定你在 Heroku 中有 EVN 变量 吗?
  • @pavan 我不这么认为,我会调查一下。感谢您的评论
  • 我认为这是 postgres 配置的问题。查看我对这个问题的回答以解决它stackoverflow.com/questions/13690162/…

标签: ruby-on-rails postgresql heroku


【解决方案1】:

在config/database.yml中,在default:&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服务器,你的应用现在应该可以运行了。

附:我注意到这个问题是在一年前提出的,并且您当时已经找到了解决方案。但是我把这个解决方案放在这里给任何可能面临同样问题的人,因为我在两天前遇到了这个问题,我花了一些时间才找到适合我的解决方案。

【讨论】:

  • 此解决方案有效。关于为什么设置这些很重要的任何指示?我最近搬到了 Windows 平台。很难配置项目克隆。该项目是在ubuntu中设置的。在那里没有发现任何问题。
  • @arjun 我很高兴它也对你有用。但老实说,我不知道为什么设置这些很重要。对不起。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      • 2020-06-08
      • 2014-06-16
      • 1970-01-01
      相关资源
      最近更新 更多