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()

Comments

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.