|Version 3 (modified by russellm, 9 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, pre .
In  or greater, the problem described on this page can be solved by providing the --noinput argument to ./manage.py, or by calling management.syncdb(interactive=False).
Disable the signal
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.
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.