Created
March 4, 2014 00:18
-
-
Save vinu76jsr/9337611 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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