Version 2 (modified by alexis smirnov, 11 years ago) (diff)

added an alternative approach

How to run 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 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 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)

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.

Back to Top