freshdb management command

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
"""
put in your project's management/commands/freshdb.py
"""

from django.core.management.base import BaseCommand

class Command(BaseCommand):
    help = "Drops and re-creates the database"

    def handle(self, *args, **options):
        from django.db import connection
        from django.conf import settings
        c = connection.cursor()
        c.execute("DROP DATABASE " + settings.DATABASE_NAME)
        c.execute("CREATE DATABASE " + settings.DATABASE_NAME)
        print 'Created new database: %s' % settings.DATABASE_NAME
        c.close()

More like this

  1. Auto-create Django admin user during syncdb by statico 3 years, 5 months ago
  2. backupdb command by msaelices 4 years, 12 months ago
  3. Fail Faster: unsafe_test Management Command by majgis 10 months, 1 week ago
  4. Configurable defaults for contrib.sites default Site during syncdb by chrischambers 1 year, 9 months ago
  5. Binding pre-existing tables with dynamically created class models by rodsenra 5 years, 11 months ago

Comments

(Forgotten your password?)