Context Navigation


How to run manage.py syncdb without being prompted to create a superuser

This applies only to post-magic-removal versions of Django, pre [3660].

In [3660] 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.

fromdjango.coreimport management
fromdjango.dispatchimport dispatcher
fromdjango.contrib.auth.managementimport create_superuser
fromdjango.contrib.authimport models as auth_app
fromdjango.db.modelsimport 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:

defcreate_superuser(app, created_models):
 fromdjango.contrib.auth.modelsimport User
 if User in created_models:
 fromdjango.contrib.auth.create_superuserimport createsuperuser
 importsettings
 createsuperuser(settings.SUPERUSER, settings.SUPERUSER_EMAIL, settings.SUPERUSER_PASSWORD)

Above code will create superuser based on the settings of your project.

Last modified 19 years ago Last modified on Sep 14, 2006, 7:52:16 AM
Note: See TracWiki for help on using the wiki.
Back to Top