无法使用Django manage.py创建超级用户

问题描述 投票:25回答:2

尝试为我的数据库创建超级用户:

manage.py createsuperuser

得到一个悲伤的递归消息:

由于未在TTY中运行,因此跳过了超级用户。您可以在项目中运行manage.py createsuperuser以手动创建一个。

严重Django?真的吗?

我找到的唯一信息是上面列出的信息,但它不起作用:Unable to create superuser in django due to not working in TTY

而另一个在这里,基本上是相同的:Can't Create Super User Django

python django python-3.x django-admin django-1.8
2个回答
62
投票

如果你跑

$ 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 '...'):

为了能够像往常一样在Windows上运行python命令以及我通常做的是在~/.profile文件中附加别名行,即

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

执行此操作后,要么获取~/.profile文件,要么只需重新启动终端,初始命令python manage.py createsuperuser应该按预期工作!


0
投票

尝试使用命令:sudo docker exec -i <container_name> sh在docker容器中创建超级用户时遇到了同样的问题。添加选项-t解决了问题:

sudo docker exec -it <container_name> sh

© www.soinside.com 2019 - 2024. All rights reserved.