5

I have a little problem here, I have a django app, that, somehow, in production DB created a row in a table that doesn't exists, with the same name as other row that does exists, ok, this might sound strange, but my question in really simple:

I have a DB in heroku that I can't delete, and I want to delete a single row of a table, or even that table (and only that one), but I don't know how to do it.

How can I do it?

Sascuash
  • 3,661
  • 10
  • 46
  • 65

3 Answers3

10

you can use the heroku cli with heroku pg:psql to connect directly to your PG instance and then issue and SQL commands you want to. Alternatively use a GUI connected to the database (info in the DATABASE_URL config key from heroku config) and do it from there.

John Beynon
  • 37,398
  • 8
  • 88
  • 97
  • Is there a way using heroku toolbelt or even django commands like http://stackoverflow.com/questions/10768112/how-to-drop-a-single-table-in-heroku-for-django-app? – Sascuash Mar 20 '13 at 16:06
  • Using the `pg:psql` command is better for deleting. The dataclips feature within Heroku won't let me issue delete queries, but I have no issues from the console. – charlesdeb Apr 02 '20 at 10:04
4

I'm a little late here, but this might help someone who stumbles across this thread...

If you go to your Heroku app's dashboard (through the website) > settings > "Reveal Config Vars" > DATABASE_URL, and then paste that URL into the browser.

I use TablePlus for database management, when I paste the link into the browser it asks if it can open TablePlus and then I can edit my production database in real time like I would in development.

I'm not sure what pasting the URL into the browser will do if you don't have TablePlus. I imagine it will request to open any other SQL management app you might have.

Mason
  • 121
  • 4
2

Connect to Heroku database by using

heroku console

and then type the command as below modifying the table and column names as necessary (or post the column names and criteria you wish to find the record to be deleted).

User.find(1).destroy
Parry
  • 177
  • 3
  • 16
  • I could not run `console`. Got a command does not exist errors. What I did was to run `heroku run python manage.py shell` and the type the command to destroy. – Original BBQ Sauce Sep 02 '19 at 16:00