Ruby-on-rails Rails + Postgres fe_sendauth:未提供密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13690162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails + Postgres fe_sendauth: no password supplied
提问by bigpotato
Hi I'm trying to hook up postgresql to my rails project. I'm learning testing but my tests aren't running because of a postgresql error about having an incorrect password:
嗨,我正在尝试将 postgresql 连接到我的 Rails 项目。我正在学习测试,但我的测试没有运行,因为关于密码不正确的 postgresql 错误:
Edmunds-MacBook-Pro:langexchange edmundmai$ rake test:units
rake aborted!
fe_sendauth: no password supplied
I've already read around and my pg_hba.conf file was originally already like this:
我已经阅读了,我的 pg_hba.conf 文件最初已经是这样的:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication edmundmai
here's my database.yml file in my rails project
这是我的 rails 项目中的 database.yml 文件
default: &default
adapter: postgresql
encoding: utf8
pool: 5
username: edmundmai
password:
development:
<<: *default
database: project_development
test:
<<: *default
database: project_test
production:
<<: *default
database: project_production
Does anyone know how I could fix this? We can chat if it's easier.
有谁知道我该如何解决这个问题?方便的话我们可以聊聊。
采纳答案by Thanh
First you should change:
首先你应该改变:
local all all trust
to:
到:
local all all md5
Then, You should create a super_userin PostgreSQL with usernameand password,after that adding usernameand passwordof new user to your database.ymlfile.
然后,您应该在 PostgreSQL 中使用和创建一个super_user,然后将新用户和新用户添加到您的文件中。usernamepasswordusernamepassworddatabase.yml
To create new super_user, open Pg Admin IIIand right click at the bottom Login Rolesto create new super user.
要创建新的super_user,打开Pg Admin III并右键单击底部Login Roles以创建新的超级用户。
回答by danielricecodes
Be sure that you have defined both RAILS_ENV and RACK_ENV on your production hosting server. I had a similar issue crop up where everything worked except rakeand the solution was to add RACK_ENV=production to my environment. RAILS_ENV was already set to production.
确保您已经在生产托管服务器上定义了 RAILS_ENV 和 RACK_ENV。我遇到了一个类似的问题,除了一切正常rake,解决方案是将 RACK_ENV=production 添加到我的环境中。RAILS_ENV 已经设置为生产。
export RACK_ENV=production
export RACK_ENV=production
bundle exec rake db:version
bundle exec rake db:version
You should see some output such as:
您应该会看到一些输出,例如:
Current version: 20121126151935
Current version: 20121126151935
Solution: make sure your Rails app has access to the RAILS_ENV and RACK_ENV environmental variables. Also, ensure they're both the same value.
解决方案:确保您的 Rails 应用可以访问 RAILS_ENV 和 RACK_ENV 环境变量。另外,请确保它们的值相同。
回答by andreofthecape
On your local machine under the testand developmentsections of the database.ymlfile you should change the usernameto your logged in username. The rails generator makes it the same as your appname and that will not work. The productionsection will depend on your production setup. If you use heroku you do not need to change anything there.
在您本地机器上的test和文件development部分下,database.yml您应该将 更改username为您登录的用户名。rails 生成器使它与您的 appname 相同,这将不起作用。该production部分将取决于您的生产设置。如果您使用 heroku,则无需在那里更改任何内容。
回答by Kras
You need only to create the user/passw and schema(db) in postgres with pgadmin and put user/passw in database.yml. When I tryed to create database with rake db:create in current rails project folder, it failed, and trowed to me error could't create for postgreSQL adapter. After that I created the schema for rails project with pgadmin, everyrthing is fine without any changes in pg_hba.conf.
您只需要使用 pgadmin 在 postgres 中创建 user/passw 和 schema(db) 并将 user/passw 放在 database.yml 中。当我尝试在当前的 rails 项目文件夹中使用 rake db:create 创建数据库时,它失败了,并向我报告了无法为 postgreSQL 适配器创建错误。之后,我使用 pgadmin 创建了 Rails 项目的架构,在 pg_hba.conf 中没有任何更改,一切都很好。

