Opened 9 years ago
Last modified 9 years ago
#25304 closed New feature
Trying to create a super user before first migrate raise a database error — at Initial Version
Reported by: | Maxime Lorant | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.