3

I'm trying to do this tutorial from Heroku.

http://devcenter.heroku.com/articles/multiple-environments

However, when I try to do this command:

heroku rake db:migrate --remote staging

I'm getting this error:

rake aborted!
Invalid DATABASE_URL

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

With --trace:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
Invalid DATABASE_URL
(erb):9:in `rescue in <main>'
(erb):6:in `<main>'
/usr/ruby1.9.2/lib/ruby/1.9.1/erb.rb:753:in `eval'
/usr/ruby1.9.2/lib/ruby/1.9.1/erb.rb:753:in `result'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.3/lib/rails/application/configuration.rb:106:in `database_configuration'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/railtie.rb:68:in `block (2 levels) in <class:Railtie>'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:42:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/base.rb:2190:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/railties/databases.rake:6:in `block (2 levels) in <top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `load'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `<main>'
Tasks: TOP => db:migrate => db:load_config

Anyone here have the similar experience? Thank you so much.

Ben
  • 1,370
  • 17
  • 42

3 Answers3

5

Had the same issue, and finally figured it out. Here are the steps I used to get this working:

  1. Type heroku config --remote REMOTE_NAME (or --app APP_NAME). Notice that DATABASE_URL is not set.
  2. For apps where the DATABASE_URL is not set, add the Postgres database addon by typing heroku addons:add heroku-postgresql:dev --remote REMOTE_NAME
  3. Make the newly-added Postgres database the default DB for the app by typing heroku pg:promote DB_NAME_FROM_STEP_2 --remote REMOTE_NAME, where DB_NAME_FROM_STEP_2 is of the form HEROKU_POSTGRESQL_COLOR_URL (with COLOR being something like RED or GRAY)

And that's it! Don't forget to do a heroku run rake db:migrate --remote REMOTE_NAME after you've pushed in order to migrate the Heroku database.

References:

user456584
  • 86,427
  • 15
  • 75
  • 107
1

Try running

heroku config

You'll see a list of production configuration variables. If you're missing the DATABASE_URL variable, that's your problem. You need to add a database. To get the small free one, run

heroku addons:add shared-database

More info here: https://devcenter.heroku.com/articles/database#troubleshooting or Heroku app crashed, receiving "Invalid DATABASE URL" when attempting heroku rake db:migrate

Community
  • 1
  • 1
Leopd
  • 41,333
  • 31
  • 129
  • 167
1

your command should be

heroku rake db:migrate --app <HEROKU APP NAME>

is as it appears in 'My Apps'.

I've never used the --remote flag, always --app which works fine. Not sure if it's a typo in their article.

UPDATE: It appears --remote uses the git remote name you have setup for that app, but I've not used that myself personally but know --app works.

John Beynon
  • 37,398
  • 8
  • 88
  • 97
  • Hi John, Thanks for the quick response, I tried your solution however, the error still occurs. :( – Ben Jan 10 '12 at 02:00