2011-12-28 9 views
7

MODIFICA: il consiglio generale è di utilizzare lo stack CEDAR.Heroku on Rails - DATABASE_URL non valido

Abbastanza nuovo a RoR, Gemme, Heroku e Git. A seguito di tutorial: http://ruby.railstutorial.org/book/ruby-on-rails-tutorial

funziona senza problemi su localhost, quando distribuito a Heroku ottenuto errore ConnectionNotEstablished, che è stato risolto qui: https://stackoverflow.com/questions/7542745/heroku-error-activerecordconnectionnotestablished(BTW: seguendo lo stesso tutorial) Dopo aver cambiato database di produzione a PostgreSQL (gemma 'pg ') genera un altro errore:

rechino sito live

An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

provato questo - Heroku app crashed, receiving "Invalid DATABASE URL" when attempting heroku rake db:migrate - Heroku rake db: migrate

rake aborted! 
Invalid DATABASE_URL 

Tasks: TOP => db:migrate => db:load_config 
(See full trace by running task with --trace) 

console Heroku

Internal server error 

Gemfile

source 'http://rubygems.org' 

gem 'rails', '3.1.1' 

group :development do 
    gem 'rspec-rails', '2.6.1' 
    gem 'annotate', '~> 2.4.1.beta' 
    gem 'sqlite3' 
end 

group :test do 
    gem 'rspec-rails', '2.6.1' 
    gem 'webrat', '0.7.1' 
    gem 'sqlite3' 
end 

group :production do 
    gem 'pg' 
end 

group :assets do 
    gem 'sass-rails', '~> 3.1.4' 
    gem 'coffee-rails', '~> 3.1.1' 
    gem 'uglifier', '>= 1.0.3' 
end 

tronchi Heroku

9:02+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:143:in `run!' 
9:02+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/bin/thin:6:in `<top (required)>' 
9:02+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:177:in `run_command' 
9:02+00:00 app[web.1]: from /home/heroku_rack/heroku.ru:18:in `block (2 levels) in <main>' 
9:02+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize' 
9:02+00:00 app[web.1]: from /usr/ruby1.9.2/bin/thin:19:in `<main>' 
9:02+00:00 app[web.1]: from /usr/ruby1.9.2/bin/thin:19:in `load' 
9:03+00:00 heroku[web.1]: State changed from starting to crashed 
9:04+00:00 heroku[web.1]: Process exited 
1:58+00:00 heroku[slugc]: Slug compilation started 
3:09+00:00 heroku[api]: Deploy 3dea426 by [email protected] 
3:09+00:00 heroku[api]: Release v7 created by [email protected] 
3:09+00:00 heroku[web.1]: State changed from crashed to created 
3:09+00:00 heroku[web.1]: State changed from created to starting 
3:10+00:00 heroku[slugc]: Slug compilation finished 
3:12+00:00 heroku[web.1]: Starting process with command `thin -p 44881 -e production -R /home/heroku_rack/heroku.ru start` 
3:15+00:00 app[web.1]: (erb):9:in `rescue in <main>': Invalid DATABASE_URL (RuntimeError) 
3:15+00:00 app[web.1]: from (erb):6:in `<main>' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/1.9.1/erb.rb:753:in `eval' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/1.9.1/erb.rb:753:in `result' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/application/configuration.rb:106:in `database_configuration' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/railtie.rb:68:in `block (2 levels) in <class:Railtie>' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `each' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:2190:in `<top (required)>' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `block in require' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:225:in `load_dependency' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:489:in `load_missing_constant' 
3:15+00:00 app[web.1]: from /app/app/models/user.rb:12:in `<top (required)>' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `each' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `const_missing' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:124:in `block in constantize' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:123:in `each' 
3:15+00:00 a 
from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:123:in `constantize' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/string/inflections.rb:43:in `constantize' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:348:in `require_or_load' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:181:in `block in const_missing' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/params_wrapper.rb:148:in `_default_wrap_model' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/params_wrapper.rb:167:in `_set_wrapper_defaults' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/params_wrapper.rb:128:in `inherited' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in wi 

3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with' 
3:15+00:00 app[web.1]: from /app/app/controllers/users_controller.rb:1:in `<top (required)>' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `block in require' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:225:in `load_dependency' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:348:in `require_or_load' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:302:in `depend_on' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:214:in `require_dependency' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:417:in `block (2 levels) in eager_load!' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:416:in `each' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:416:in `block in eager_load!' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:414:in `each' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:414:in `eager_load!' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/application/finisher.rb:51:in `block in <module:Finisher>' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `instance_exec' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `run' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:55:in `block in run_initializers' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `each' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `run_initializers' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/application.rb:96:in `initialize!' 
3:15+00:00 app[web.1]: from /app/config/environment.rb:5:in `<top (required)>' 
3:15+00:00 app[web.1]: from <internal:lib/rubygems/custom_require>:29:in `require' 
3:15+00:00 app[web.1]: from <internal:lib/rubygems/custom_require>:29:in `require' 
3:15+00:00 app[web.1]: from config.ru:3:in `block (3 levels) in <main>' 
3:15+00:00 app[web.1]: from /home/heroku_rack/heroku.ru:23:in `eval' 
3:15+00:00 app[web.1]: from /home/heroku_rack/heroku.ru:23:in `block (3 levels) in <main>' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `method_missing' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:120:in `new' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:120:in `map' 
3:15+00:00 app[web.1]: from /home/heroku_rack/heroku.ru:18:in `block (2 levels) in <main>' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize' 
3:15+00:00 app[web.1]: from /home/heroku_rack/heroku.ru:11:in `new' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize' 
3:15+00:00 app[web.1]: from /home/heroku_rack/heroku.ru:11:in `block in <main>' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval' 
3:15+00:00 app[web.1]: from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize' 
3:15+00:00 app[web.1]: from /home/heroku_rack/heroku.ru:1:in `new' 
3:15+00:00 app[web.1]: from /home/heroku_rack/heroku.ru:1:in `<main>' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/rack/adapter/loader.rb:36:in `eval' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/rack/adapter/loader.rb:36:in `load' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/controllers/controller.rb:175:in `load_rackup_config' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/controllers/controller.rb:65:in `start' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:143:in `run!' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/bin/thin:6:in `<top (required)>' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/bin/thin:19:in `load' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/bin/thin:19:in `<main>' 
3:15+00:00 app[web.1]: from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:177:in `run_command' 
3:16+00:00 heroku[web.1]: State changed from starting to crashed 
3:17+00:00 heroku[web.1]: Process exited 
5:55+00:00 heroku[router]: Error H10 (App crashed) -> GET high-wind-7473.heroku.com/pages/home dyno= queue= wait= service= status=503 bytes= 
5:57+00:00 heroku[router]: Error H10 (App crashed) -> GET high-wind-7473.heroku.com/pages/home dyno= queue= wait= service= status=503 bytes= 

di tipo bloccato, si prega di aiutare (punto nella giusta direzione)

Naturalmente

bundle install 
git add . 
git commit -m "another heroku fix" 
git push 
git push heroku 

risposta

2

prima cosa mi piacerebbe iniziare con sta spostando il applicazione al Cedar Stack - supporta Rails 3.1 out of the box senza dover fare alcun casino.

Quando si crea la tua applicazione tramite heroku create farlo come

heroku create --stack cedar 

e poi repush a questo stack - si possono trovare i vostri problemi saranno tutti svanire. La cosa da ricordare è aggiungere 'esegui' i tuoi comandi, heroku esegui la console, heroku esegui rake db: esegui la migrazione ecc.

0

Puoi digitare heroku config --long - (nome app). Pubblica i risultati, in particolare DATABASE_URL.

Ulteriori informazioni. Inoltre, assicurati di essere sulla pila di cedri come menzionato sopra.

+0

BUNDLE_WITHOUT => sviluppo: prova LANG => en_US.UTF-8 RACK_ENV => produzione Migrazione a cedro, come suggerito in altra risposta pure. –

+0

La migrazione al cedro non è così banale, alcuni problemi con postgre/sqlite La prossima volta userà ** - database = postgresql ** fin dall'inizio. Comunque grazie per l'aiuto, per ora completerò il tutorial senza la distribuzione ... –

+0

Manca l'URL del database .... hai installato il database condiviso? Dovrebbe sputare l'URL del database e sotto l'URL del database condiviso. Se c'è un problema, sembra che sia lì. Ci dovrebbe essere almeno un valore predefinito. –

3

Ho avuto esattamente lo stesso problema. Si è scoperto che non avevo un database associato all'app. Lo vedrai con il semplice comando heroku config-- dovresti vedere alcuni URL di database che puntano ad Amazon.ad esempio:

$ h config 
DATABASE_URL  => postgres://fakedexgwa:[email protected]/fakedexgwa 

Comunque, ho risolto questo con la creazione di una nuova applicazione e la distribuzione ad esso. Ho provato a trafficare nelle schermate di configurazione, ma non ho potuto risolvere il problema.

Non sono sicuro se questa è la stessa causa della tua: ho creato una semplice app Ruby, l'ho implementata e poi ho creato un'app Rails. Non ero ancora arrivato a nessun database, e mi chiedo se Heroku abbia in qualche modo deciso sulla prima implementazione che non avevo bisogno di un database.

+0

Hey chiamami pazzo, ma potresti voler cambiare la tua vera password db o modificare questo post, in modo che le credenziali del database non vengano trasmesse al mondo? – culix

+0

Ehi pazzo! Ho cambiato il post in modo che sia più evidentemente dati falsi ... fyi Non ho inserito le mie reali credenziali in origine. – ndp

+0

Ok, uffa! Buono a sapersi! Sto solo cercando di aiutare. – culix

17

È necessario impostare la variabile di ambiente DATABASE_URL con il percorso per il file db postgres online.

Prova a eseguire heroku pg. Se l'output è "myapp non ha database heroku-postgresql". quindi devi prima aggiungere il componente aggiuntivo PostgreSQL. Creerà un db postgres per te su Amazon AWS.

heroku addons:add heroku-postgresql:hobby-basic 

(hobby di base è il piano gratuito)

Per trovare l'URL per il nuovo database, eseguire

heroku config 

si dovrebbe vedere una variabile che inizia con HEROKU_POSTGRESQL. Copia il suo valore (si dovrebbe iniziare con postgres:// e utilizzarlo per impostare il DATABASE_URL

heroku config:set DATABASE_URL=postgres://your-db-url 
1

Si prega di leggere questo articolo:

ClearDB MySQL Database

Comandi:

heroku config

o se si utilizza per una rotaie proiettare più progetti Heroku

heroku config --app your_app_name

Aggiungi URL del database:

heroku config:set DATABASE_URL='mysql://adffdadf2341:[email protected]/heroku_db?reconnect=true'

Se si utilizza mysql2 gemma deve sostituire MySQL con mysql2

heroku config:set DATABASE_URL='mysql2://adffdadf2341:[email protected]/heroku_db?reconnect=true'

spero quelle configurazioni possono essere utilizzati per il database PostgreSQL, NoSQL o un altro database.