Version 2 (modified by 18 years ago) ( diff ) | ,
---|
How to run manage.py syncdb
without being prompted to create a superuser
This applies only to post-magic-removal versions of Django.
In my project I found it annoying being prompted to create a superuser everytime I ran manage.py syncdb
or from my custom installation script management.syncdb()
. Delving a little deeper I found that I could disable this by "disconnecting" django.contrib.auth.mangement.create_superuser
from the new event dispatcher in Django.
The following snippet does just that.
from django.core import management from django.dispatch import dispatcher from django.contrib.auth.management import create_superuser from django.contrib.auth import models as auth_app from django.db.models import signals dispatcher.disconnect(create_superuser, sender=auth_app, signal=signals.post_syncdb) management.syncdb()
Now if I could only make management.syncdb()
less verbose.
alternative approach
Another alternative is to change the implementation of django.contrib.auth.mangement.create_superuser
to the following:
def create_superuser(app, created_models): from django.contrib.auth.models import User if User in created_models: from django.contrib.auth.create_superuser import createsuperuser import settings createsuperuser(settings.SUPERUSER, settings.SUPERUSER_EMAIL, settings.SUPERUSER_PASSWORD)
Above code will create superuser based on the settings
of your project.