我刚刚升级到Rails 3.1,我try 部署到Heroku的第一个应用遇到了与Postgres adapter相关的问题.我可以将应用程序推送到heroku,但当我try 迁移数据库时,我会出现以下错误:

heroku rake db:迁移

rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` 
(pg is not part of the bundle. Add it to Gemfile.)
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)

当我try 他们建议的安装时,我得到:

ERROR:  Could not find a valid gem 'activerecord-postgresql-adapter' (>= 0) in any repository
ERROR:  Possible alternatives: activerecord-postgis-adapter, activerecord-jdbcpostgresql-adapter, activerecord-postgresql-cursors, activerecord-jdbcmysql-adapter, activerecord-jdbcmssql-adapter

这已经很奇怪了...那么,如果不是他们说我应该安装什么,我应该安装什么样的Ruby 才能让它工作呢??

当我try 安装gem pg时,我得到:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

/Users/jerometufte/.rvm/rubies/ruby-1.9.2-p180/bin/ruby 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 need configuration options.

Provided configuration options:
    --with-opt-dir
    ...

我目前正在使用SQLite3.非常感谢您的帮助,这让我很困惑.

推荐答案

备选方案1:

pg添加到Gemfile,但不要try 在本地安装.

$ cat Gemfile
...
group :production do
  # gems specifically for Heroku go here
  gem "pg"
end

# Skip attempting to install the pg gem
$ bundle install --without production

选项2(Debian/Ubuntu):

pg添加到Gemfile中,但首先安装先决条件.

$ cat Gemfile
...
group :production do
  # gems specifically for Heroku go here
  gem "pg"
end

# Install the pg gem's dependencies first
$ sudo apt-get install libpq-dev
# Then install the pg gem along with all the other gems
$ bundle install

Postgresql相关问答推荐

Postgres:创建分区需要很长时间

在rust中,有什么方法可以从sqlx::query_with中返回rows_infected以及行本身?

在特定距离内创建点的唯一索引

PostgresQL:获取两个数组之间的对应数量

PostgreSQL 中基于时间戳的移动平均线

SQLAlchemy 中使用什么类型存储字节字符串?

Rails 重置所有 Postgres 序列?

如何将 DELETE 的返回值插入到 postgresql 中的 INSERT 中?

SQL:当谈到 NOT IN 和 NOT EQUAL TO 时,哪个更有效,为什么?

PostgreSQL 提示:You will need to rewrite or cast the expression. column "state" is of type status but expression is of type character varying

如何 Select 列值为空的行?

无法识别的配置参数bytea_output

无法使用 sequelize 从本地 node 应用程序连接到 heroku postgresql 数据库

在 PostgreSQL 中显示正在运行的查询的全文

Rails 验证数组中的值

使用 Hibernate 查询:colon gets treated as parameter / escaping colon

使用 RPostgreSQL 写入特定模式

如何在 postgres 查询中排名

调用 getNextException 来查看原因:如何让 Hibernate / JPA 显示异常的数据库服务器消息

性能调优:为布尔列创建索引