如何在Heroku中为Django应用程序放置一个表 [英] How to drop a single table in Heroku for Django app
问题描述
我看到如何将Django中的全部数据库放在英雄中(破坏Heroku上的Postgres DB )。但是,我只想放几个表(基本上在python manage.py sqlclear appname中执行sql命令)。如何做到这一点?
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?
推荐答案
嘿,这是很直接的。你应该只是一个查看功能,您可以在其中处理原始SQL。我昨天试图解决一个postgres唯一的索引同步问题。
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:将其映射到一些URL,然后访问浏览器中的url,该函数将执行。
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
这篇关于如何在Heroku中为Django应用程序放置一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!