ruby-on-rails - 将数据库从 SQLite 更改为 Postgresql : "gem install pg" error?

标签 ruby-on-rails ruby postgresql sqlite

我已尽一切努力将我的数据库更改为 Postgresql。

1)我试过从自制软件卸载和安装 2)我试过从 www.postgresql.org 安装 postgresql

但是它们都不起作用..当我尝试安装“gem pg”时遇到了同样的错误

 $bundle install
 .
 .
 Installing pg 0.17.1 with native extensions

 Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

 current directory: /private/var/folders/jd/dn7zyf593n97j1rdjbbh_hl00000gn/T/bundler20151201-657-1v67eg6pg-0.17.1/gems/pg-0.17.1/ext
 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20151201-657-kkjx98.rb extconf.rb --with-pg config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
  Using config values from /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
  sh: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config: No such file or directory
  sh: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config: No such file or directory
  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
  need configuration options.

  Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--with-pg
--without-pg
--with-pg-config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/

  To see why this extension failed to compile, please check the mkmf.log which can be found here:

 /var/folders/jd/dn7zyf593n97j1rdjbbh_hl00000gn/T/bundler20151201-657-1v67eg6pg-0.17.1/extensions/universal-darwin-15/2.0.0/pg-0.17.1/mkmf.log

  extconf failed, exit code 1

  Gem files will remain installed in /var/folders/jd/dn7zyf593n97j1rdjbbh_hl00000gn/T/bundler20151201-657-1v67eg6pg-0.17.1/gems/pg-0.17.1 for inspection.
 Results logged to /var/folders/jd/dn7zyf593n97j1rdjbbh_hl00000gn/T/bundler20151201-657-1v67eg6pg-0.17.1/extensions/universal-darwin-15/2.0.0/pg-0.17.1/gem_make.out


 An error occurred while installing pg (0.17.1), and Bundler cannot continue.
 Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

gem 文件

 gem 'rails', '4.2.4'
 gem 'sdoc', '~> 0.4.0', group: :doc

 gem 'bootstrap-sass', '~> 3.2.0'
 gem 'autoprefixer-rails'
 gem 'pg', '0.17.1' 

 group :development, :test do

 gem 'sqlite3'
 gem 'byebug'
 gem 'web-console', '~> 2.0'
 gem 'spring'

 end

 group :production do
 gem 'rails_12factor', '0.0.2'
 gem 'puma',           '2.11.1'
 end

数据库.yml

default: &default
adapter: sqlite3
pool: 5
timeout: 5000

development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: ****
password: <!--- this place is **EMPTY** -->

test:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: ****
password: <!--- this place is **EMPTY** -->

production:
 <<: *default
 database: db/production.sqlite3

最佳答案

您必须提供 pg_config 的路径。你会找到答案 here .

关于ruby-on-rails - 将数据库从 SQLite 更改为 Postgresql : "gem install pg" error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34022930/

相关文章:

ruby-on-rails - Mongoid,查找名称包含字符串的模型

ruby - 解决 Sinatra 路由方法中缺乏上下文的问题

ruby - 未安装 gem 依赖项

ruby-on-rails - 由于字段不存在而创建不保存记录

python - OpenERP 在父记录中创建记录时将值从父记录传递到子记录

javascript - 单页应用程序和 CSRF token

ruby-on-rails - 如果 after_initialize 回调返回 false,则返回 nil 对象

sql - 使用返回的 id 在 1 个查询中的 3 个表中插入多行

ruby-on-rails - 无法安装 json gem 1.8.6 - 无法在 Ubuntu 上构建 gem native 扩展

sql - 不同的查询,相同的结果(看起来),完全不同的性能......为什么?