简体   繁体   中英

Unable to create superuser in django due to not working in TTY

I go through first django tutorial from djangoproject.com and at the very beginning of part 2, which is creating superuser when I run "python manage.py createsuperuser" I get the following message back:

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

I get the same message when I go on to create superuser after running syncdb .

I am working on Eclipse for Windows 7, and Django 1.7.1 together with Python 2.7.8.

When using the Git Bash and to correct the above error message try to append winpty
ie for example:

$ winpty python manage.py createsuperuser
Username (leave blank to use '...'):

if you are in virtualenv, cd into your virtualenv and activate it. then try these steps:

python manage.py syncdb --noinput
python manage.py migrate
python manage.py createsuperuser

You can create a superuser using django shell ( python manage.py shell )

from django.contrib.auth.models import User
User.objects.create_superuser(username='YourUsername', password='hunter2', email='your@email.com')

I am a Windows10 user. I tried to run py manage.py createsuperuser command using Git Bash console, but error has been thrown. Then I switched Git Bash to native Windows Command Line with administrator privileges , and re-run command - it was working.

Use "Windows PowerShell" or "Windows Cmd" and then use same command. Git command interface has some restriction.

First run

$ django-admin startproject mysite in cmd prompt,then apply migration by

cd mysite mysite:

python manage.py makemigrations then

python manage.py migrate after that

python manage.py createsuperuser

From Django 3.0 you can do it without TTY

    DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=psw \
    python manage.py createsuperuser --email=admin@admin.com --noinput

also, you can set DJANGO_SUPERUSER_PASSWORD as the environment variable

Use this command :

python3 manage.py makemigrations

python3 manage.py migrate

python3 manage.py createsuperuser

python manage.py runserver

Your error is probably:

[Error `You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, content types, sessions.
Run 'python manage.py migrate' to apply them.

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
    return Database.Cursor.execute(self, query, params)`][1]

check you yo directory with Tree command: tree

Then run Make migration : enter image description here

then create superuser with the python3 manage.py createsuperuser command :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM