0

当我尝试使用 postgres db 创建新的 rails 应用程序时,我无法完成 rake 命令。

这就是我所做的。

sayth@sayth-TravelMate-5740G:~$ sudo -u postgres psql postgres
[sudo] password for sayth: 
psql (9.2.4)
Type "help" for help.

postgres=# create role sayth login createdb;
ERROR:  role "sayth" already exists

postgres=# DROP user sayth;
DROP ROLE
postgres=# create role sayth login createdb;
CREATE ROLE
postgres=# initdb -D /usr/local/pgsql/data
postgres-# \q
sayth@sayth-TravelMate-5740G:~$ 

我已经创建了我的rails应用程序

rails new testapp2 -d postgres

在观看 Railscast 后意识到为什么它不起作用http://railscasts.com/episodes/342-migrating-to-postgresql

所以我编辑了 config/database.yml

development:
  adapter: postgresql
  encoding: unicode
  database: testapp2_development
  pool: 5
  username: sayth
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: testapp2_test
  pool: 5
  username: sayth
  password:

但仍然 rake 不会创建我的数据库。

sayth@sayth-TravelMate-5740G:~/testapp2$ rake db:create:all
FATAL:  Peer authentication failed for user "testapp2"
...
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"testapp2_production", "pool"=>5, "username"=>"testapp2", "password"=>nil}

似乎我已经阅读了很多并尝试了我发现的任何东西,但不确定该怎么做。

该命令也失败。

sayth@sayth-TravelMate-5740G:~/testapp2/config$ psql -U postgres
psql: FATAL:  Peer authentication failed for user "postgres"
4

1 回答 1

1

该错误仅在创建生产数据库时,在这里您指定了错误的用户,“testapp2”而不是“sayth”

于 2013-08-18T03:14:52.643 回答