Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to create super user with Django manage.py

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: Unable to create superuser in django due to not working in TTY

And this other one here, which is basically the same: Can't Create Super User Django

like image 847
gerosalesc Avatar asked Sep 11 '15 22:09

gerosalesc


People also ask

How many superuser can be created in Django?

Note that this won't prevent from setting a user as being a superuser from django admin interface. If you want to completely make it impossible to create two superusers, you can add the constraint on the database level directly.

What is the difference between Django admin and manage py?

Django-admin.py: It is a Django's command line utility for administrative tasks. Manage.py: It is an automatically created file in each Django project. It is a thin wrapper around the Django-admin.py.

How do I know if my Django user is superuser?

So to test whether current user is superuser you can: if user.is_active and user. is_superuser: ... You can use it in template or pass this to template as variable via context.


1 Answers

If you 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.
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!

like image 90
Evgeny Bobkin Avatar answered Sep 22 '22 21:09

Evgeny Bobkin