Skip to content

Instantly share code, notes, and snippets.

@vinu76jsr
Created March 4, 2014 00:18
Show Gist options
  • Save vinu76jsr/9337611 to your computer and use it in GitHub Desktop.
Save vinu76jsr/9337611 to your computer and use it in GitHub Desktop.
# get all the unmanaged models
from django.db import connection
tables = connection.introspection.table_names()
seen_models = connection.introspection.installed_models(tables)
managed_tables = set([m._meta.db_table for m in seen_models])
extra_tables = set(tables) - managed_tables
cursor = connection.cursor()
for table in extra_tables:
try:
cursor.execute('DROP TABLE %s' % table)
except Exception as e:
print "Failed to drop %s for %s error with message %s" % (table, e, e.message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment