#25304: Trying to create a super user before first migrate raise a database 
error
--------------------------------------+--------------------
     Reporter:  mlorant               |      Owner:  nobody
         Type:  Cleanup/optimization  |     Status:  new
    Component:  contrib.auth          |    Version:  1.8
     Severity:  Normal                |   Keywords:
 Triage Stage:  Unreviewed            |  Has patch:  1
Easy pickings:  1                     |      UI/UX:  0
--------------------------------------+--------------------
 When creating a new project, you can sometimes forget to run `manage.py
 migrate` before creating the initial superuser (especially if you don't
 execute `runserver` before, which display a warning about migrations not
 applied). The resulting error make sense, it can't access to auth_user,
 since it does not exist yet:


 {{{
 $ django-admin.py startproject sample
 $ cd sample/ && python manage.py createsuperuser
 Traceback (most recent call last):
   File "manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
 [...]
   File
 "/vagrant/django/django/contrib/auth/management/commands/createsuperuser.py",
 line 85, in handle
     default_username = get_default_username()
   File "/vagrant/django/django/contrib/auth/management/__init__.py", line
 189, in get_default_username
     auth_app.User._default_manager.get(username=default_username)
 [...]
   File "/vagrant/django/django/db/backends/sqlite3/base.py", line 323, in
 execute
     return Database.Cursor.execute(self, query, params)
 django.db.utils.OperationalError: no such table: auth_user
 }}}

 ... but with a little try/except, it could be nicer and give a more
 meaningful information:

 {{{
 $ python manage.py createsuperuser
 CommandError: You must execute `manage.py migrate` once before creating a
 super user
 }}}

 I have a patch ready (as I said, it just a try/except, see attachment)
 but, if accepted, it would need unit tests to be complete.

--
Ticket URL: <https://code.djangoproject.com/ticket/25304>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.cf6bfb2f9c4bf09c08e124acb9e22705%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to