Skip to content

Instantly share code, notes, and snippets.

@kholidfu
Created February 27, 2017 15:06
Show Gist options
  • Save kholidfu/0a9471f8d732b086e8218c4866b5e9aa to your computer and use it in GitHub Desktop.
Save kholidfu/0a9471f8d732b086e8218c4866b5e9aa to your computer and use it in GitHub Desktop.
django reset all
import os
import glob
import subprocess
from sys import stdout, stdin, stderr
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
class Command(BaseCommand):
help = 'Reset all'
def handle(self, *args, **options):
basedir = os.path.abspath(settings.BASE_DIR)
dbasefile = os.path.join(basedir, 'db.sqlite3')
migrationfiles = glob.glob(os.path.join(basedir, 'web', 'migrations', '*'))
# deleting dbase file
os.remove(dbasefile)
print 'clearing DB DONE'
# deleting migration files
for f in migrationfiles:
os.remove(f)
print 'clearing migration files DONE'
# run makemigrations
makemigration_cmd = 'python manage.py makemigrations web'
migrate_cmd = 'python manage.py migrate'
createsuperuser_cmd = 'python manage.py createsuperuser'
subprocess.call(makemigration_cmd.split())
subprocess.call(migrate_cmd.split())
subprocess.call(createsuperuser_cmd.split())
print 'Done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment