[英]Unable to create superuser in django due to not working in TTY
我瀏覽了 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.
在運行syncdb
后繼續創建超級用戶時,我收到相同的消息。
我正在為 Windows 7 和 Django 1.7.1 以及 Python 2.7.8 開發 Eclipse。
使用 Git Bash 並糾正上述錯誤消息時,嘗試附加winpty
即例如:
$ winpty python manage.py createsuperuser
Username (leave blank to use '...'):
如果您在 virtualenv 中,請cd
進入您的 virtualenv 並激活它。 然后嘗試以下步驟:
python manage.py syncdb --noinput
python manage.py migrate
python manage.py createsuperuser
您可以使用 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')
我是 Windows10 用戶。 我嘗試使用Git Bash
控制台運行py manage.py createsuperuser
命令,但已拋出錯誤。 然后我將Git Bash
切換到具有管理員權限的本機Windows Command Line
,並重新運行命令 - 它正在工作。
使用“Windows PowerShell”或“Windows Cmd”,然后使用相同的命令。 Git 命令接口有一些限制。
第一次運行
$ django-admin startproject mysite 在 cmd 提示符下,然后通過以下方式應用遷移
cd mysite mysite:
python manage.py makemigrations 然后
之后 python manage.py migrate
python manage.py createsuperuser
從Django 3.0 開始,您無需 TTY 即可完成
DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=psw \
python manage.py createsuperuser --email=admin@admin.com --noinput
此外,您可以將 DJANGO_SUPERUSER_PASSWORD 設置為環境變量
使用這個命令:
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py createsuperuser
python manage.py runserver
你的錯誤可能是:
[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]
使用 Tree 命令檢查您的 yo 目錄: tree
然后運行 Make migration :在此處輸入圖像描述
然后使用python3 manage.py createsuperuser
命令創建超級用戶:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.