【问题标题】:active record postgresql adapter error in railsrails中的活动记录postgresql适配器错误
【发布时间】:2013-02-26 15:20:23
【问题描述】:

这是我的问题。我正在尝试创建一个博客。我运行'rails new blog'。在我尝试“rake db:create”之前,一切都很好。它返回一个错误:

rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adap
ter` (pg is not part of the bundle. Add it to Gemfile.)

当我尝试安装 pg 适配器时,我得到了这个:

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing activerecord-postgresql-adapter:
    ERROR: Failed to build gem native extension.

F:/Ruby200-x64/bin/ruby.exe extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
 checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may

需要配置选项。

我的宝石文件:

  source 'https://rubygems.org'

gem 'rails', '3.2.12'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem "pg"

# Gems used only for assets and not required
# in production environments by default.
 group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

有什么想法吗?

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3.1 gem


【解决方案1】:

您缺少 postgresql 的库。 你可以这样安装:

sudo apt-get install libpq-dev

也许还可以看看this old question

【讨论】:

  • 问题是我在 Windows 上工作(是的,我知道这是错误的,但我只是初学者)所以 sudo 在这里不起作用
  • 那不妨看看这个:stackoverflow.com/questions/7086654/…
【解决方案2】:

您是否安装了 Postgres?如果是这样,请确保 pg_config.exe 在 PATH 中。或者使用--with-pg-config–with-pg-dir 键:

gem install pg --with-pg-config=<path>

详情见https://github.com/ged/ruby-pg/blob/master/README-Windows.rdoc

【讨论】:

    【解决方案3】:

    卸载pg gem,并为windows安装postgres-pr

    从 Gemfile 中删除:

    gem "pg"
    

    然后放:

    gem "postgres-pr"
    

    然后运行:

    bundle installgem install postgres-pr 或者您正在安装 gems

    【讨论】:

      【解决方案4】:

      我遇到了同样的错误,我通过将正确的文件权限设置为 postgresql_adapter.rb 解决了

      cd [YOUR_ACTIVERECORD_GEM_PATH]/lib/active_record/connection_adapters
      chmod 644 postgresql_adapter.rb
      

      不知何故,postgresql_adapter.rb 的文件权限在我的计算机中被损坏了...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-01-04
        • 1970-01-01
        • 1970-01-01
        • 2013-10-16
        • 1970-01-01
        • 2021-08-15
        • 2011-06-13
        相关资源
        最近更新 更多