Rails 3.1 - 推送到 Heroku - 安装 postgres 适配器时出错?
我刚刚升级到 Rails 3.1,我尝试部署到 Heroku 的第一个应用程序遇到了与 Postgres 适配器相关的问题。我可以将应用程序推送到heroku,但是当我尝试迁移数据库时,出现以下错误:
heroku rake db:migrate
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)
当我尝试他们建议的安装时,我得到:
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
这看起来已经很奇怪了...所以到底是什么gem如果不是他们所说的我应该安装的东西,我应该安装以使这个东西正常工作吗?
当我尝试安装 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。非常感谢任何帮助,这让我感到困惑。
I just upgraded to Rails 3.1 and the first app i've tried to deploy to Heroku has encountered a problem relating to Postgres adapter. I'm able to push the app to heroku but then when i try to migrate the database i get the following error:
heroku rake db:migrate
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)
when I try their suggested install i get:
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
which already seems weird... so what exact gem should I install to get this thing working if not what they say I should install??
When I try installing gem pg i get:
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
...
I'm using SQLite3 currently. Any help greatly appreciated, this is baffling me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
选项 1:
将
pg
添加到您的Gemfile
,但跳过尝试在本地安装它。选项 2 (Debian/Ubuntu):
将
pg
添加到您的Gemfile
,但首先安装先决条件。Option 1:
Add
pg
to yourGemfile
but skip trying to install it locally.Option 2 (Debian/Ubuntu):
Add
pg
to yourGemfile
but first install the prerequisites.您肯定需要 Heroku 的 Gemfile 中的 pg。
关于您在本地遇到的错误:确保安装了 postgres,运行 gem install pq -- --with-pg-config=[pg-config 二进制文件所在的路径],然后捆绑安装。
或者,如果您的本地数据库工作正常(因为您使用的是 sqlite 或 postgres-pr),您可以将
gem 'pg'
行放入 Gemfile 中名为 production 的组中,然后 <本地代码>捆绑安装--无需生产。You definitely need pg in the Gemfile for Heroku.
About the error you're getting locally: make sure you have postgres installed, run
gem install pq -- --with-pg-config=[path to wherever your pg-config binary is]
, then bundle install.Alternatively, if your local database is working fine (either because you're using sqlite or postgres-pr), you could put the
gem 'pg'
line in your Gemfile in a group called production, thenbundle install --without production
locally.更多最新信息:这与本地 pg gem 的不同版本有关。
我已经在生产组中加入了 pg(我在本地运行 sqllite),但 Heroku 仍然在呕吐。
我的新 Rails 3.1 应用程序的问题就消失了:
当我运行
heroku run rake db:migrate
时,More up-to-date info: It had something to do with a different version of pg gem locally.
I already had pg in a production group (I run sqllite locally), but Heroku was still puking.
The problem went away for my new Rails 3.1 app when I:
worked like a charm when I then ran
heroku run rake db:migrate