Django ошибка при создании суперпользователя

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

Community's user avatar

asked Sep 11, 2015 at 22:15

gerosalesc's user avatar

6

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!

answered May 7, 2016 at 20:55

Evgeny Bobkin's user avatar

Evgeny BobkinEvgeny Bobkin

4,0622 gold badges17 silver badges21 bronze badges

3

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

winpty python manage.py createsuperuser.

jcaliz's user avatar

jcaliz

3,8712 gold badges8 silver badges13 bronze badges

answered Apr 13, 2020 at 3:12

Harsha Dhagay's user avatar

1

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

answered Apr 13, 2019 at 12:29

marke's user avatar

markemarke

1,0247 silver badges20 bronze badges

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=admin@admin.com --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=admin@admin.com --noinput

The output should say: Superuser created successfully.

answered Jan 5, 2022 at 13:09

pymen's user avatar

pymenpymen

5,53743 silver badges35 bronze badges

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.

answered Nov 15, 2019 at 18:02

darrell's user avatar

darrelldarrell

531 silver badge4 bronze badges

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

answered Nov 12, 2021 at 8:04

EILYA's user avatar

EILYAEILYA

3374 silver badges5 bronze badges

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

[ Make sure migrations are already made ]

$ django-admin createsuperuser

answered Nov 20, 2020 at 5:12

Invest41's user avatar

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 

Gino Mempin's user avatar

Gino Mempin

24.5k28 gold badges92 silver badges128 bronze badges

answered Nov 20, 2019 at 22:38

darrell's user avatar

darrelldarrell

531 silver badge4 bronze badges

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.

asked Nov 17, 2014 at 19:06

PJM's user avatar

4

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

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

answered Aug 25, 2017 at 8:11

Siv's user avatar

SivSiv

1,02619 silver badges29 bronze badges

2

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')

answered Feb 4, 2018 at 0:06

kszl's user avatar

kszlkszl

1,2061 gold badge11 silver badges18 bronze badges

1

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

answered Nov 17, 2014 at 19:15

doniyor's user avatar

doniyordoniyor

36.2k55 gold badges174 silver badges259 bronze badges

4

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

answered Nov 21, 2016 at 7:03

Shiv Kumar Sah's user avatar

Shiv Kumar SahShiv Kumar Sah

1,1241 gold badge13 silver badges16 bronze badges

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.

answered Oct 25, 2016 at 15:01

Fusion's user avatar

FusionFusion

4,9575 gold badges42 silver badges49 bronze badges

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

answered May 17, 2019 at 8:04

Voontent's user avatar

VoontentVoontent

6995 silver badges8 bronze badges

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

answered Jan 5, 2022 at 13:12

pymen's user avatar

pymenpymen

5,53743 silver badges35 bronze badges

If you are Windows user using GitBash terminal and trying to create super for admin it won’t work instead of that use command prompt in administrative privilege it works

Gitbash terminal error

$ 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.

Error Resolved Using Command Prompt

python manage.py createsuperuser
Username (leave blank to use 'user'): admin
Email address:
Password:
Password (again):
The password is too similar to the username.
This password is too short. It must contain at least 8 characters.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

This might be helpful for others. Do Upvote for this if it works for you

answered Feb 8, 2022 at 12:42

Mohammed Shakeeb's user avatar

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 createsuperusercommand :

Baum mit Augen's user avatar

answered Dec 3, 2019 at 11:06

Ravi Ranjan's user avatar

Я пытаюсь создать суперпользователя, чтобы получить доступ к инфраструктуре администратора Django в моем приложении. Я использую Vagrant на машине Windows 8.1:

> ./manage.py createsuperuser

Однако я получаю следующую ошибку:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, i
n execute_from_command_line
    utility.execute()
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, i
n execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in ru
n_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in ex
ecute
    output = self.handle(*args, **options)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsu
peruser.py", line 141, in handle
    self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
  File "/vagrant/myapp/accounts/managers.py", line 52, in create_superuser
    return self._create_user(email, password, True, True, **extra_fields)
  File "/vagrant/myapp/accounts/managers.py", line 31, in _create_user
    user.set_slug()
  File "/vagrant/myapp/accounts/models.py", line 164, in set_slug
    slug = slugify(self.username, max_length=50).lower()
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/slugify/main.py", line 101, in slugify
    text = join_words(words, separator, max_length)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/slugify/main.py", line 78, in join_words
    text = next(words)    # text = words.pop(0)
StopIteration

Я читал в другом месте (здесь) и (здесь), что это проблема «локали», но я понимаю, что это ошибка OSX, и я нахожусь в бродяжной виртуальной машине…?

#python #sql #django

Вопрос:

Я довольно новичок в джанго. Внезапно я столкнулся с этой ошибкой при попытке создать суперпользователя из командной строки Windows с помощью

 python manage.py createsuperuser
 

Когда я ввожу его, я получаю эту ошибку

 django.db.utils.OperationalError: no such table: auth_user
 

Я создал совершенно новую виртуальную среду и проект, но я продолжаю сталкиваться с этой проблемой. Кто-нибудь видел это раньше?

Комментарии:

1. может быть, сначала нужно сделать миграцию? python manage.py migrate

Ответ №1:

Как показывает ошибка, такой таблицы нет auth_user .

auth_user это таблица, в которой будет храниться информация о пользователе, но которая еще не была создана в базе данных.

Для этого выполните команду;

 python manage.py migrate
 

Попытка создать суперпользователя для моей базы данных:

manage.py createsuperuser

Получение грустного рекурсивного сообщения:

Создание суперпользователя пропущено из-за отсутствия работы в TTY. Вы можете запустить manage.py createsuperuser в своем проекте, чтобы создать его вручную.

Серьезно Django? Серьезно?

Единственная информация, которую я нашел для этого, была приведена выше, но она не работала:
Невозможно создать суперпользователя в django из-за отсутствия работы в TTY

И этот другой здесь, который в основном тот же:
Невозможно создать суперпользователя Django

4b9b3361

Ответ 1

Если вы запустите

$ 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.

из Git Bash и обратитесь к приведенному выше сообщению об ошибке, попробуйте добавить winpty

i.e, например:

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

Чтобы иметь возможность запускать команды python, как обычно, в Windows, а также то, что я обычно делаю, это добавить строку псевдонима в файл ~/.profile i.e.

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

После этого либо отправьте файл ~/.profile, либо просто перезапустите терминал, а начальная команда python manage.py createsuperuser должна работать как ожидалось!

Ответ 2

Я собираюсь предположить, что если вы используете manage.py createsuperuser, а не python manage.py createsuperuser, вы используете команду из среды IDE или какой-либо другой странной среды. Попробуйте запустить python manage.py createsuperuser вне вашей среды разработки, и он должен работать. В идеале вы бы использовали виртуальную среду или virtualenvwrapper.

Ответ 3

У меня была такая же проблема при попытке создать суперпользователя в контейнере докера с помощью команды: sudo docker exec -i <container_name> sh. Добавление опции -t решило проблему:

sudo docker exec -it <container_name> sh

Понравилась статья? Поделить с друзьями:
  • Display inf ошибка
  • Django ошибка got an unexpected keyword argument
  • Django ошибка 405
  • Display exe системная ошибка
  • Django ошибка 400