eclipse 由于不在 TTY 中工作,无法在 django 中创建超级用户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26980003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:13:29  来源:igfitidea点击:

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

pythondjangoeclipsetty

提问by PJM

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:

我浏览了 djangoproject.com 上的第一个 django 教程,在第 2 部分的开头,即在我运行时创建超级用户时,"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.    

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

当我在运行后继续创建超级用户时收到相同的消息syncdb

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

我正在为 Windows 7 和 Django 1.7.1 以及 Python 2.7.8 开发 Eclipse。

回答by Siv

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

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

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

回答by doniyor

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

如果您在 virtualenv 中,请cd进入您的 virtualenv 并激活它。然后尝试以下步骤:

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

回答by kszl

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

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

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

回答by Fusion

I am a Windows10 user. I tried to run py manage.py createsuperusercommand using Git Bashconsole, but error has been thrown. Then I switched Git Bashto native Windows Command Linewith administrator privileges, and re-run command - it was working.

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

回答by Shiv Kumar Sah

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

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

回答by blueboy21

First run

第一次运行

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

$ django-admin startproject mysite 在 cmd 提示符下,然后应用迁移

cd mysite mysite:

cd mysite mysite:

python manage.py makemigrations then

python manage.py makemigrations 然后

python manage.py migrate after that

之后 python manage.py migrate

python manage.py createsuperuser

python manage.py createsuperuser

回答by Ravi Ranjan

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

使用 Tree 命令检查您的 yo 目录:tree

Then run Make migration : enter image description here

然后运行 ​​Make migration : 在此处输入图像描述

then create superuser with the python3 manage.py createsuperusercommand :

然后使用以下python3 manage.py createsuperuser命令创建超级用户: