[英]Unable to connect to local PostgreSQL database
I created a simple rails application: 我创建了一个简单的rails应用程序
1 1
$ rails new myapp1 -d postrgresql
$ rails new myapp1 -d postrgresql
2 . 2 。 Removed
/public/index.html
删除了
/public/index.html
3 . 3 。 Created the Homecontroller and the actions
创建了Homecontroller和动作
4 . 4 。 Wrote the routes
写了路线
myapp1::Application.routes.draw do
myapp1 :: Application.routes.draw做
root :to => "home#index" match 'about' => 'home#about' match 'contacts' => 'home#contacts' match 'projects' => 'home#projects' end
5 . 5 。 Created the views and the default layout
创建了视图和默认布局
6 . 6 。 The bottom line.
底线。 Here is the database.yml
这是database.yml
development:
发展:
adapter: postgresql encoding: unicode database: myapp1_db host: localhost pool: 5 username: myapp1_user password: 1234 test: adapter: postgresql encoding: unicode database: myapp1_db host: localhost pool: 5 username: myapp1_user password: 1234 production: adapter: postgresql encoding: unicode database: myapp1_db host: localhost pool: 5 username: myapp1_user password: 1234
and of course I created user and database 当然我创建了用户和数据库
sudo -u postgres psql
postgres=# \password
postgres=# create user myapp1_user with password '1234';
postgres=# create database myapp1_db owner myapp1_user;
But there are some worries: 但有一些担忧:
1 . 1 。 Now I don't use any database, but in spite of this the application gives an error
现在我不使用任何数据库,但尽管如此,应用程序仍然出错
PG::Error FATAL: Peer authentication failed for user "myapp1"
PG ::错误致命:用户“myapp1”的对等身份验证失败
2 . 2 。 It seems like rails turns a blind eye to
database.yml
. 看起来rails似乎对
database.yml
视而不见。 Why does it use the user myapp1 instead of myapp1_user ? 为什么它使用用户myapp1而不是myapp1_user ?
Whitespace is significant in YAML. 空白在YAML中很重要。
production:
adapter: postgresql
encoding: unicode
...
password: 1234
Should be: 应该:
production:
adapter: postgresql
encoding: unicode
...
password: 1234
Provide host and port in the database.yml file, like this: 在database.yml文件中提供主机和端口,如下所示:
development:
adapter: postgresql
encoding: unicode
database: myapp1_db
host: localhost
pool: 5
username: myapp1_user
password: 1234
host: localhost
port: 5432
Works like a charm on Ubuntu 12.04 LTS with Rails 3.2.x and PostgreSQL 9.1.x 在Ubuntu 12.04 LTS上使用Rails 3.2.x和PostgreSQL 9.1.x就像魅力一样
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.