public
Created

An alternative approach to drop all tables in django project

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.