eclipse 无法在django中创建超级用户,因为无法在TTY中工作

hpcdzsge  于 2023-10-18  发布在  Eclipse
关注(0)|答案(9)|浏览(143)

我在djangoproject.com上浏览了第一个django教程,在第2部分的开头,当我运行"python manage.py createsuperuser"时创建超级用户,我得到了以下消息:

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

在运行syncdb之后,我继续创建超级用户时得到相同的消息。
我正在开发Eclipse for Windows 7,Django 1.7.1和Python 2.7.8。

guicsvcw

guicsvcw1#

当使用Git Bash并纠正上述错误消息时,尝试追加winpty
例如:

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

cxfofazt2#

您可以使用django shell(python manage.py shell)创建超级用户

  1. from django.contrib.auth.models import User
  2. User.objects.create_superuser(username='YourUsername', password='hunter2', email='[email protected]')
5kgi1eie

5kgi1eie3#

如果你在virtualenv中,cd进入你virtualenv并激活它。然后尝试这些步骤:

  1. python manage.py syncdb --noinput
  2. python manage.py migrate
  3. python manage.py createsuperuser
qybjjes1

qybjjes14#

使用“Windows PowerShell”或“Windows Cmd”,然后使用相同的命令。Git命令接口有一些限制。

2w2cym1i

2w2cym1i5#

我是Windows10用户。我尝试使用Git Bash控制台运行py manage.py createsuperuser命令,但出现错误。然后我用管理员权限Git Bash切换到本机Windows Command Line,并重新运行命令-它工作正常。

31moq8wy

31moq8wy6#

从Django 3.0开始,你可以在没有TTY的情况下做到这一点

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

此外,您还可以将DJANGO_SUPERUSER_PASSWORD设置为环境变量

2ekbmq32

2ekbmq327#

如果你是Windows用户,使用GitBash终端,并试图创建超级管理员,它不会工作,而不是使用命令提示符在管理权限它的作品
Gitbash终端错误

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

使用命令提示符解决的错误

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

这可能对其他人有帮助。如果它对你有效,请为它投票

展开查看全部
kzmpq1sx

kzmpq1sx8#

首次运行

  1. $ django-admin startproject mysite

在cmd提示符下,然后通过以下方式应用迁移

  1. cd mysite
  2. mysite:
  3. python manage.py makemigrations

然后

  1. python manage.py migrate

之后

  1. python manage.py createsuperuser
展开查看全部
7jmck4yq

7jmck4yq9#

使用以下命令:

  1. python3 manage.py makemigrations
  2. python3 manage.py migrate
  3. python3 manage.py createsuperuser
  4. python manage.py runserver

你的错误可能是:

  1. [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.
  2. Run 'python manage.py migrate' to apply them.
  3. Traceback (most recent call last):
  4. File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
  5. return self.cursor.execute(sql, params)
  6. File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
  7. return Database.Cursor.execute(self, query, params)`][1]

用Tree命令检查你的目录:tree
然后运行Make migration:enter image description here
然后使用python3 manage.py createsuperuser命令创建超级用户:

展开查看全部

相关问题