All Django management commands can be accessed programmatically:
from django.core.management import call_command
call_command('syncdb', interactive=True)
Ideally you’d use a pre-init signal on runserver
to activate this, but such a signal doesn’t exist. So, actually, the way I’d handle this if I were you would be to create a custom management command, like runserver_newdb
, and execute this inside it:
from django.core.management import call_command
call_command('syncdb', interactive=True)
call_command('runserver')
See the documentation for more information on writing custom management commands.