1

我正在尝试将我的 Rails 应用程序迁移到 PostGreSql,以便在与 heroku 相同的环境中工作......

我在我的 Mac 上安装了 postgres、pg 和 postgres-pr,但我无法让 Taps 将我的数据库从 Heroku 拉到我的 postgresql 服务器上。

我的 Rails 应用程序无缝连接到数据库。

当我遇到 irb 这就是我得到的:

>> require "rubygems"
=> false
>> require "sequel"
=> true
>> DB = Sequel.postgres
NameError: uninitialized constant Sequel::Postgres::PGError
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/adapters/postgres.rb:89
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `k_require'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/core.rb:249:in `tsk_require'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/core.rb:72:in `check_requiring_thread'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/core.rb:69:in `synchronize'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/core.rb:69:in `check_requiring_thread'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/core.rb:249:in `tsk_require'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/database/connecting.rb:25:in `adapter_class'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/database/connecting.rb:63:in `connect'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/core.rb:119:in `connect'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/core.rb:282:in `adapter_method'
    from /Library/Ruby/Gems/1.8/gems/sequel-3.17.0/lib/sequel/core.rb:289:in `postgres'
    from (irb):3
>> 

我不明白出了什么问题。

有人有想法吗?


这就是我得到的杰里米

BigMac:~ jp$ ruby -rubygems -rpg -e "p PGError"
ruby: no such file to load -- pg (LoadError)
BigMac:~ jp$ ruby -rubygems -rpostgres -e "p PGError"
ruby: no such file to load -- postgres (LoadError)

我不确定“检查路径中某处的 pg.rb 或 postgres.rb”是什么意思

我应该扫描 $PATH 中的所有目录并查找不需要的 pg.rb 或 postgres.rb 文件吗?


这很奇怪,因为我确实安装了 pg 和 postgre

这是我刚刚跑的

BigMac:/ jp$ sudo gem install pg
Password:
Building native extensions.  This could take a while...
Successfully installed pg-0.10.0
1 gem installed
Installing ri documentation for pg-0.10.0...
Installing RDoc documentation for pg-0.10.0...
BigMac:/ jp$ ruby -rubygems -rpg -e "p PGError"
ruby: no such file to load -- pg (LoadError)
BigMac:/ jp$ 
4

3 回答 3

3

I was running into the exact same problem trying to run heroku db:pull to my local postgresql database using the pg gem. Randomly ended up fixing the problem by removing the following gems:

activerecord-jdbc-adapter 
activerecord-jdbcpostgresql-adapter

Tried it again after removing those gems and managed to pull from heroku successfully. Try checking your gem file for any gems that relate to postgres other than your pg gem and remove it. All the best

于 2011-02-22T09:40:14.043 回答
1

出于某种原因,您需要的任何 postgres 或 pg 文件都没有定义 PGError 类。检查路径中某处的 pg.rb 或 postgres.rb。

当您对以下内容进行 ruby​​ 时会发生什么:

ruby -rubygems -rpg -e "p PGError"
ruby -rubygems -rpostgres -e "p PGError"
于 2010-12-01T15:32:45.917 回答
1

如果您查看postgres 适配器源代码,您可以看到它尝试加载pgRuby gem,然后是postgresgem(按此顺序优先)。根据您的输出,ruby -rubygems -rpg -e "p PGError"您没有gem,您的系统上pg也没有安装 gem。postgres

确保您运行gem install pg并再次尝试该行,如果这不起作用,它将成为 Rubygems 问题而不是 Sequel 问题。如果您能够加载,pg那么PGError将被定义。

于 2010-12-03T11:58:55.457 回答