Skip to content

Instantly share code, notes, and snippets.

@atiw003
Forked from lqez/gist:1520810
Created June 28, 2012 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atiw003/3008778 to your computer and use it in GitHub Desktop.
Save atiw003/3008778 to your computer and use it in GitHub Desktop.
An alternative approach to drop all tables in django project
#!/usr/bin/python
# Alternative approach.
import os
import MySQLdb
print 'drop remaining tables...'
for name, db in settings.DATABASES.iteritems():
conn = MySQLdb.connect( db['HOST'], db['USER'], db['PASSWORD'], db['NAME'] )
c = conn.cursor()
c.execute('SET FOREIGN_KEY_CHECKS=0');
c.execute('SHOW TABLES')
for table in c.fetchall():
print '\t', table[0]
c.execute('DROP TABLE %s' % table[0])
c.execute('SET FOREIGN_KEY_CHECKS=1');
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment