Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
dropping tables in django database
#!/usr/bin/python
import os
import settings
fn = 'drop_tables.sql'
try:
os.remove( fn )
except:
pass
print 'Preparing sql commands for dropping...'
os.system( 'echo "SET FOREIGN_KEY_CHECKS=0;" >> %s' % ( fn ) )
for app in reversed(settings.INSTALLED_APPS):
appname = app.split('.')[-1]
print '\t', appname
res = os.system( './manage.py sqlclear %s >> %s' % ( appname, fn ) )
os.system( 'echo "SET FOREIGN_KEY_CHECKS=1;" >> %s' % ( fn ) )
f = open( fn, 'r' )
c = 0
for l in f:
if l.find('DROP TABLE') >= 0:
c += 1
f.close()
print c, 'tables will be dropped.'
os.system( './manage.py dbshell < drop_tables.sql' );
os.remove( fn );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.