2011-09-04 17 views
38

Ho appena eseguito l'upgrade a Rails 3.1 e la prima app che ho provato a distribuire su Heroku ha riscontrato un problema relativo all'adattatore Postgres. Sono in grado di spingere l'applicazione per Heroku, ma poi quando provo a migrare il database ottengo il seguente errore:Rails 3.1 - Pushing to Heroku - Errori durante l'installazione dell'adattatore Postgres?

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) 

quando provo il loro suggerite Installare ottengo:

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 

che sembra già strano ... così che cosa gioiello esatta dovrei installare per ottenere questa cosa di lavoro, se non quello che dicono che dovrei installare ??

Quando provo l'installazione gioiello pg ottengo:

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 
    ... 

sto utilizzando SQLite3 attualmente. Qualsiasi aiuto molto apprezzato, questo mi sconcerta.

+0

Come impostare PostgreSQL per Rails e Heroku http: // robdodson .me/blog/2012/04/27/how-to-setup-postgresql-for-rails-and-heroku/ –

risposta

41

Opzione 1:

Aggiungi pg al tuo Gemfile ma saltare cercando di installarlo localmente.

$ 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 

Opzione 2 (Debian/Ubuntu):

Aggiungi pg al Gemfile ma prima installare i prerequisiti.

$ 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 
+0

Cool si ho finito col fare il secondo. Se diventa fastidioso mantenere postgresql a livello locale, allora forse lo abbandonerò, spero di non rimpiangere questa decisione. – tuddy

+0

Aggiungi un commento al tuo 'README'. – yfeldblum

4

Hai sicuramente bisogno di pg nel Gemfile per Heroku.

Informazioni sull'errore che si sta verificando localmente: assicurarsi di aver installato Postgres, eseguire gem install pq -- --with-pg-config=[path to wherever your pg-config binary is], quindi installare bundle.

In alternativa, se il database locale sta funzionando benissimo (sia perché si sta utilizzando SQLite o Postgres-pr), si potrebbe mettere la linea gem 'pg' nel vostro Gemfile in una produzione gruppo chiamato, quindi bundle install --without production localmente.

1

più up-to-date informazioni: Aveva qualcosa a che fare con una versione diversa di pg gioiello a livello locale.

Ho già partecipato a un gruppo di produzione (eseguo sqllite localmente), ma Heroku stava ancora vomitando.

Il problema è andato via per il mio nuovo Rails 3.1 app quando ho:

rm Gemfile.lock 
touch Gemfile 
bundle install 
git add . 
git commit -am "wiped Gemfile.lock re-ran bundle install" 
git push heroku master 

funzionato come un fascino quando ho poi corse heroku run rake db:migrate