Rails 不使用 Postgres 用户帐户
我在 Ubuntu 10.10 上使用 Rails 3.0 和 PostgreSQL 8.4,并在 Ruby 1.9.2p136 上使用 pg gem。当我运行rake db:migrate
时,我收到错误FATAL:用户“my_os_user_account”的密码身份验证失败
,而我实际上希望它以 my_db_username 身份登录到数据库在database.yml中指定。
我在 pg_hba.conf 中为 Unix 套接字和 IP 连接配置了 md5 身份验证,并且可以在命令行上使用 psql
登录。我也尝试过将身份验证设置为信任。然后,psql
允许我无需输入密码即可登录,但 Rails 随后给出FATAL:角色“my_os_user_account”不存在
。
这是database.yml:
development:
adapter: postgresql
database: my_project_dev
user: my_db_username
password: my_password
pool: 5
timeout: 5000
带有用于测试和生产的附加几乎相同的条目。
I'm using Rails 3.0 and PostgreSQL 8.4 on Ubuntu 10.10 and Ruby 1.9.2p136 with the pg gem. When I run rake db:migrate
, I get the error FATAL: password authentication failed for user "my_os_user_account"
, when I actually expected it to log in to the database as my_db_username specified in database.yml.
I have md5 authentication configured in pg_hba.conf for both Unix socket and IP connections and I can log in using psql
on the command line. I have also tried setting the authentication to trust. psql
then allows me to log in without entering a password, but Rails then gives FATAL: role "my_os_user_account" does not exist
.
Here's database.yml:
development:
adapter: postgresql
database: my_project_dev
user: my_db_username
password: my_password
pool: 5
timeout: 5000
with additional near-identical entries for test and production.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实上,
username
的正确键是username
而不是user
。容易出错,容易修复。The correct key for
username
is, in fact,username
and notuser
. Easy mistake, easy fix.我有类似的问题。然而,我的问题是在database.yml 中用括号括住实际的用户名和密码,如“[admin]...[passowrd]”,这适用于 ruby 1.8.7,但不适用于较新的版本。为此花了整整一天的时间。读完这篇文章后我意识到可能就是这样。 (耸肩)希望这对其他人有帮助。
I had a similar problem. However, my issue was brackets around the actual username and passowrd in database.yml like this "[admin]... [passowrd]", this works for ruby 1.8.7, but not newer versions. Spent an entire aggravating day on this. I realized that might be it after reading this article. (shrug) Hope this helps someone else.