Heroku on Rails - Invalid DATABASE_URL Heroku on Rails - Invalid DATABASE_URL heroku heroku

Heroku on Rails - Invalid DATABASE_URL


You need to set the DATABASE_URL environment variable with the path to your online postgres db.

Try running heroku pg. If the output is "myapp has no heroku-postgresql databases." then you need to add the PostgreSQL add-on first. It will create a postgres db for you on Amazon AWS.

heroku addons:add heroku-postgresql:hobby-basic

(hobby-basic is the free plan)

To find the URL for your new database, run

heroku config

You should see a variable that starts with HEROKU_POSTGRESQL. Copy its value (it should start with postgres:// and use it to set the DATABASE_URL

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


I had exactly the same problem. It turned out I didn't have a database associated with the app. You will see this with the simple heroku config command-- you should see some database URLs there pointing to Amazon. eg:

$ h configDATABASE_URL        => postgres://fakedexgwa:fakepassword@ec2-33-44-55-77.compute-1.amazonaws.com/fakedexgwa

Anyway, I fixed this by creating a brand new app and deploying to it. I tried fiddling around in the config screens, but couldn't fix the problem.

I'm not sure if this is the same cause as yours: I created a simple Ruby app, deployed it, and then created a Rails app. I hadn't gotten to any database yet, and I'm wondering if Heroku somehow decided on the first deployment that I didn't need a database.


First thing I'd start with is moving your application to the Cedar Stack - it supports Rails 3.1 out of the box without having to do any messing around.

When you create your app via heroku create do it as

heroku create --stack cedar

and then repush to this stack - you may find your problems will all vanish. The thing to remember is to add 'run' into your commands, heroku run console, heroku run rake db:migrate etc.