postgresql Rails 3.1 - 推送到 Heroku - 安装 postgres 适配器时出错?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7296683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails 3.1 - Pushing to Heroku - Errors installing postgres adapter?
提问by tuddy
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:
我刚刚升级到 Rails 3.1,我尝试部署到 Heroku 的第一个应用程序遇到了与 Postgres 适配器相关的问题。我可以将应用程序推送到 heroku,但是当我尝试迁移数据库时,出现以下错误:
heroku rake db:migrate
heroku 耙分贝:迁移
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??
这看起来已经很奇怪了......那么如果不是他们说我应该安装的东西,我应该安装什么确切的 gem 来让这个东西工作?
When I try installing gem pg i get:
当我尝试安装 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
...
I'm using SQLite3 currently. Any help greatly appreciated, this is baffling me.
我目前正在使用 SQLite3。非常感谢任何帮助,这让我感到困惑。
回答by yfeldblum
Option 1:
选项1:
Add pg
to your Gemfile
but skip trying to install it locally.
添加pg
到您的Gemfile
但跳过尝试在本地安装它。
$ 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
Option 2 (Debian/Ubuntu):
选项 2(Debian/Ubuntu):
Add pg
to your Gemfile
but first install the prerequisites.
添加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
回答by Michael Fairley
You definitely need pg in the Gemfile for Heroku.
您肯定需要在 Heroku 的 Gemfile 中使用 pg。
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.
关于您在本地遇到的错误:确保已安装 postgres,运行gem install pq -- --with-pg-config=[path to wherever your pg-config binary is]
,然后捆绑安装。
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, then bundle install --without production
locally.
或者,如果您的本地数据库工作正常(因为您使用的是 sqlite 或 postgres-pr),您可以将gem 'pg'
Gemfile 中的该行放在名为 production 的组中,然后放在bundle install --without production
本地。
回答by jpw
More up-to-date info: It had something to do with a different version of pg gem locally.
更多最新信息:它与本地不同版本的 pg gem 有关。
I already had pg in a production group (I run sqllite locally), but Heroku was still puking.
我已经在一个生产组中有 pg(我在本地运行 sqllite),但 Heroku 仍然在呕吐。
The problem went away for my new Rails 3.1 app when I:
当我执行以下操作时,我的新 Rails 3.1 应用程序的问题就消失了:
rm Gemfile.lock
touch Gemfile
bundle install
git add .
git commit -am "wiped Gemfile.lock re-ran bundle install"
git push heroku master
worked like a charm when I then ran heroku run rake db:migrate
当我跑的时候就像一个魅力 heroku run rake db:migrate