17

I am trying to share a database between two apps on Heroku according to Share database between 2 apps in Heroku but setting up database_url on the second app gives an error:

$ heroku config:add DATABASE_URL=postgres://...
Setting config vars and restarting pacific-headland-1960... failed  
 !    Cannot destroy last attachment to billing app for resource loving-subtly-5807
Community
  • 1
  • 1
user1167937
  • 441
  • 1
  • 8
  • 18

2 Answers2

27

DATABASE_URL is what's currently storing your second app's connection to its provisioned DB, which Heroku is kindly preventing you from deleting because there are no other references to it.

First, remove the second application's DB. Anything in it will be destroyed.

heroku addons:destroy heroku-postgresql:<your DB tier> --app <your second app>

If these are new apps, your DB tier is probably hobby-dev, but you can check for it by running heroku addons --app <your second app>.

Then, you'll be able to set DATABASE_URL on the second app.

If you want to have the second app connected to both DBs, you'll need to store the first app's DB URL in a different environment variable and update your second app's code to use it.


Unrelated to your question, you've just pasted your DB credentials into a public space. You should roll them with heroku pg:credentials --reset --app <your first application>.

Docs: https://devcenter.heroku.com/articles/heroku-postgresql

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Kristján
  • 18,165
  • 5
  • 50
  • 62
  • Woow I browsed back to this question and saw what I copypasted - wow it is too early for me to post on the internet ;) – user1167937 Jun 03 '15 at 06:13
  • 1
    I feel ya :-D Definitely still roll the creds since there's an [edit history](https://stackoverflow.com/posts/30611801/revisions) – Kristján Jun 03 '15 at 06:30
  • 1
    Kristjan if you dont mind a followup, I try to connect to the database with 'heroku pg:psql' but it says: 'Your app has no databases.'. According to documentation this command should fall on DATABASE_URL. Would you have any idea why I cant connect? – user1167937 Jun 03 '15 at 06:48
  • I would've guessed Heroku just uses the configured `DATABASE_URL` for that too, but maybe the CLI is looking at your addons, which now app 2 doesn't have. You should still be able to run `pg:psql` on app 1, where the database addon is present. – Kristján Jun 03 '15 at 06:54
0

From Heroku

Previously to add an add-on you could use the command addons:add. That command is now deprecated in favor of the create command.

NSTJ
  • 3,858
  • 2
  • 27
  • 34