Not able to create super user with Django manage.py

PythonDjangoPython 3.xDjango AdminDjango 1.8

Python Problem Overview


Trying to create a super user for my database:

manage.py createsuperuser

Getting a sad recursive message:

Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser in your project to create one manually.

Seriously Django? Seriously?

The only information I found for this was the one listed above but it didn't work: https://stackoverflow.com/questions/26980003/unable-to-create-superuser-in-django-due-to-not-working-in-tty

And this other one here, which is basically the same: https://stackoverflow.com/questions/14059573/cant-create-super-user-django

Python Solutions


Solution 1 - Python

If you run

$ python manage.py createsuperuser
Superuser creation skipped due to not running in a TTY. You can run $ python manage.py createsuperuser
Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser in your project to create one manually. in your project to create one manually.
from Git Bash and face the above error message try to append winpty i.e. for example:
$ winpty python manage.py createsuperuser
Username (leave blank to use '...'):
To be able to run python commands as usual on windows as well what I normally do is appending an alias line to the ~/.profile file i.e.

 MINGW64 ~$ cat ~/.profile
 alias python='winpty python'

After doing so, either source the ~/.profile file or simply restart the terminal and the initial command python manage.py createsuperuser should work as expected!

Solution 2 - Python

In virtualenv, for creating super-user for Django project related to git-bash use the command:

winpty python manage.py createsuperuser.

Solution 3 - Python

I had same problem when trying to create superuser in the docker container with command: sudo docker exec -i <container_name> sh. Adding option -t solved the problem:

sudo docker exec -it <container_name> sh

Solution 4 - Python

To create an admin username and password, you must first use the command:

python manage.py migrate

Then after use the command:

python manage.py createsuperuser

Once these steps are complete, the program will ask you to enter:

  • username
  • email
  • password

With the password, it will not show as you are typing so it will appear as though you are not typing, but ignore it as it will ask you to renter the password. When you complete these steps, use the command:

python manage.py runserver

In the browser add "/admin", which will take you to the admin site, and then type in your new username and password.

Solution 5 - Python

Since Django 3.0 you can create a superuser without TTY in two ways

Way 1: Pass values and secrets as ENV in the command line

    DJANGO_SUPERUSER_USERNAME=admin2 DJANGO_SUPERUSER_PASSWORD=psw \
    python manage.py createsuperuser --email[email protected] --noinput

Way 2: set DJANGO_SUPERUSER_PASSWORD as the environment variable

# .admin.env
DJANGO_SUPERUSER_PASSWORD=psw

# bash
source '.admin.env' && python manage.py createsuperuser --username=admin [email protected] --noinput

The output should say: Superuser created successfully.

Solution 6 - Python

I tried creating superuser from Stash [ App: Pythonista on iOS ]

[ Make sure migrations are already made ]

$ django-admin createsuperuser

Solution 7 - Python

Check your docker-compose.yml file and make sure your django application is labeled by web under services.

Solution 8 - Python

I figured out how to do so. What I did was I went to VIEWS.py. Next, I imported the module os. Then I created a function called createSuperUser(request):. Then, I then created a variable called admin and set it equal to os.system("python manage.py createsuperuser"). Then after that, return admin. Finally, I restarted the Django site, then it will prompt you in the terminal.

import os

def createSuperUser(request):
    admin = os.system("python manage.py createsuperuser")
    return 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongerosalescView Question on Stackoverflow
Solution 1 - PythonEvgeny BobkinView Answer on Stackoverflow
Solution 2 - PythonHarsha DhagayView Answer on Stackoverflow
Solution 3 - PythonmarkeView Answer on Stackoverflow
Solution 4 - PythondarrellView Answer on Stackoverflow
Solution 5 - PythonpymenView Answer on Stackoverflow
Solution 6 - PythonInvest41View Answer on Stackoverflow
Solution 7 - PythonEILYAView Answer on Stackoverflow
Solution 8 - PythondarrellView Answer on Stackoverflow