【问题标题】:Why is PostgreSQL telling me a schema doesn't exist?为什么 PostgreSQL 告诉我模式不存在?
【发布时间】:2012-05-23 11:10:15
【问题描述】:

我在使用 Rails 进行敏捷 Web 开发(第 4 版)的第 7 章,当我运行 rake test:units 时,我收到以下错误:

rake aborted!
PG::Error: ERROR: invalid value for parameter "search_path": "public" 
DETAIL: schema "public" does not exist
: SET search_path TO public

Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)

我使用的是装有 OSX 10.7.4 的 MacBook Pro。我有 Ruby 1.9.3、Rails 3.1.0、Rake 0.9.2.2 和 PostgreSQL 9.1。我的生产、开发和测试数据库都存在,已迁移到并匹配我的 config/database.yml 文件中的名称、用户和密码。它们的架构都是公开的。

谁能帮帮我?

【问题讨论】:

  • 您用来连接到 postgres 的用户有权访问该架构?尝试用命令行连接

标签: ruby-on-rails unit-testing postgresql rake


【解决方案1】:

根据错误消息,架构public 不存在。你检查过,它在那里吗?它只是另一个可以像其他任何模式一样删除的模式。

【讨论】:

  • 所有三个数据库,开发、生产和测试,都有一个公共模式和一个使用rake db:migrate 的表。我从命令行执行所有这些操作,特别是使用 iTerm。
【解决方案2】:

来自http://www.postgresql.org/docs/9.1/static/infoschema-schemata.html(强调我自己的):

​视图架构包含当前数据库中由当前启用的角色拥有的所有架构

如果您与默认用户 (postgres) 以外的用户连接,public 架构可能不会显示。 (是的,即使该用户创建并拥有数据库,public 架构也归 postgres [1] 所有。)

[1]http://archives.postgresql.org/pgsql-general/2008-10/msg01320.php

【讨论】:

    【解决方案3】:

    确保您的用户默认数据库具有公共架构。

    例如,如果您使用用户“postgres”连接到数据库,那么应该有一个名为“postgres”的数据库,其架构名为“public”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-12
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 2016-08-05
      相关资源
      最近更新 更多