I see how to drop your entire DB in heroku in Django ( Destroying a Postgres DB on Heroku). However, I want to just drop a few tables (basically perform the sql commands in 'python manage.py sqlclear appname'). How do I do this?
Asked
Active
Viewed 2,833 times
2
-
I haven't used Heroku in a while, but shouldn't you be capable of getting DB CLI access? From there, you just have to execute the SQL. – Thomas Orozco May 26 '12 at 17:39
-
Isn't [South](http://south.readthedocs.org/en/latest/index.html) enough ? – Alireza Savand May 27 '12 at 10:41
-
i actually am having this problem because I messed up my South configuration.. – fangsterr May 27 '12 at 18:59
2 Answers
6
Hey this is pretty straight forward. You should just make a view function in which you can process raw SQL. I JUST did this yesterday trying to solve a postgres unique index syncing problem.
Views.py: Map this to some URL then visit the url in browser and the function will execute.
from django.db import connection, transaction
def dropTable(request):
cursor = connection.cursor()
cursor.execute(“DROP TABLE WHATEVER”) //custom raw SQL goes here
success = simplejson.dumps({‘success’:’success’,}) //I do this as a success message
return HttpResponse(success, mimetype=’application/json’) //you'll need an import or two for the json stuff to work

Hacking Life
- 3,335
- 2
- 19
- 20
-
2I think you should also add the statement for committing the changes to the DB in your answer above: `transaction.commit_unless_managed()` – Arpit Rai Feb 08 '13 at 17:19
1
I had the same problem when I came across this post and I think there is an easier way to resolve this issue. Heroku rolled out PostgreSQL Studio, a web based PSQL UI that allows you to view your DB and PSQL commands.
Once you've connected to your DB, just open a worksheet and run
TRUNCATE TABLE table_name;

jaredsb
- 11
- 1