8

奇怪的错误。所有帮助表示赞赏。

这是我的 database.yml

development:
  adapter: postgresql
  encoding: unicode
  database: app_development
  pool: 5
  username: username
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: app_test
  pool: 5
  username: username
  password:

production:
  adapter: postgresql
  encoding: unicode
  database: app_production
  pool: 5
  username: username
  password:

例如,当我手动创建数据库并尝试使用它们时,rake db:test:preare我收到以下错误:

FATAL:  database "postgres" does not exist

当我尝试删除数据库时,出现以下错误:

Couldn't drop app_development : #<PG::Error: FATAL:  database "postgres" does not exist
>
Couldn't drop app_test : #<PG::Error: FATAL:  database "postgres" does not exist
>
Couldn't drop app_production : #<PG::Error: FATAL:  database "postgres" does not exist

如果我尝试通过 with 创建数据库,rake db:create:all则会收到以下错误:

app_development already exists
app_test already exists
app_production already exists

所以看来我的 database.yml 没问题。但由于某种原因,它正在寻找一个名为 postgres 的数据库,而这不是我的 database.yml 中的内容。

任何帮助表示赞赏。

编辑:

这里更多来自 rake 的踪迹:

无法为 {"adapter"=>"postgresql"、"encoding"=>"unicode"、"database"=>"app_production"、"pool"=>5、"username"=>"username" 创建数据库“密码”=>无}

4

3 回答 3

5
于 2012-12-04T16:32:20.327 回答
2

你还没有说你是否真的有一个 postgres 数据库,这是错误所抱怨的。

大概不会,这个“rake”工具正在以用户 postgres 的身份连接到数据库 postgres,因此它可以创建新的数据库。显然,它需要以某人的身份进行连接才能做任何事情。

请花时间浏览 PostgreSQL 手册并了解如何启用/控制日志记录。从长远来看,它将为您提供良好的服务。我猜也有 rake/rails 的调试/日志设置。

于 2012-06-02T08:54:58.583 回答
0

我正在使用 Mac OS X,我在使用 python 和 sqlalchemy 时遇到了同样的问题。就像 Flavio 建议的那样,检查 postgresapp 并检查如何连接部分。

from sqlalchemy import create_engine
engine = create_engine('postgresql://localhost/[YOUR_DATABASE_NAME]')
于 2020-03-11T09:14:07.867 回答