无法在 Django、Virtualenv 中创建超级用户
Not able to create super user in Django, Virtualenv
我正在尝试在 Django 中创建超级用户,但一直收到此错误消息。
Superuser creation skipped due to not running in a TTY. You can run `manage.py createsuperuser` in your project to create one manually.
我首先尝试了 eclipse 自定义命令,然后我看到有人可以使用 window 命令行和 virtualenv 创建超级用户,所以我安装并激活了它。但是直到现在我还无法创建超级用户。我在 cmd 中输入的是
C:\Users\name>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python manage.py createsuperuser
File "<stdin>", line 1
python manage.py createsuperuser
^
SyntaxError: invalid syntax
我也试过了。
C:\Users\name>python manage.py createsuperuser
python: can't open file 'manage.py': [Errno 2] No such file or directory
从终端创建超级用户的命令是,
python manage.py createsuperuser
但是你必须从 django 项目目录 运行 这个命令。找不到 manage.py 的事实意味着你不在项目目录中。你必须先 cd 进去。
您正在 python 控制台中创建超级用户。不要那样做。通过 cmd 和 运行 命令转到 manage.py 所在的位置。然后你可以创建超级用户。
运行 这个命令来自你的项目目录
[projectname]/
├── [appname]/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
在这里你应该运行这个来自项目名称目录。
使用这个命令:
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py createsuperuser
python manage.py runserver
我猜你的错误是:[错误`你有 14 个未应用的迁移。在您为应用程序应用迁移之前,您的项目可能无法正常工作:管理、身份验证、内容类型、会话。
运行 'python manage.py migrate' 应用它们。
回溯(最近调用最后):
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py”,第 85 行,在 _execute 中
return self.cursor.execute(sql, 参数)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py”,第 303 行,在执行中
return Database.Cursor.execute(自身、查询、参数)`]1
用 Tree 命令检查你的目录:tree
然后运行进行迁移:
enter image description here
然后使用 python3 manage.py createsuperuser
命令创建超级用户:
我正在尝试在 Django 中创建超级用户,但一直收到此错误消息。
Superuser creation skipped due to not running in a TTY. You can run `manage.py createsuperuser` in your project to create one manually.
我首先尝试了 eclipse 自定义命令,然后我看到有人可以使用 window 命令行和 virtualenv 创建超级用户,所以我安装并激活了它。但是直到现在我还无法创建超级用户。我在 cmd 中输入的是
C:\Users\name>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python manage.py createsuperuser
File "<stdin>", line 1
python manage.py createsuperuser
^
SyntaxError: invalid syntax
我也试过了。
C:\Users\name>python manage.py createsuperuser
python: can't open file 'manage.py': [Errno 2] No such file or directory
从终端创建超级用户的命令是,
python manage.py createsuperuser
但是你必须从 django 项目目录 运行 这个命令。找不到 manage.py 的事实意味着你不在项目目录中。你必须先 cd 进去。
您正在 python 控制台中创建超级用户。不要那样做。通过 cmd 和 运行 命令转到 manage.py 所在的位置。然后你可以创建超级用户。
运行 这个命令来自你的项目目录
[projectname]/
├── [appname]/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
在这里你应该运行这个来自项目名称目录。
使用这个命令:
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py createsuperuser
python manage.py runserver
我猜你的错误是:[错误`你有 14 个未应用的迁移。在您为应用程序应用迁移之前,您的项目可能无法正常工作:管理、身份验证、内容类型、会话。 运行 'python manage.py migrate' 应用它们。
回溯(最近调用最后): 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py”,第 85 行,在 _execute 中 return self.cursor.execute(sql, 参数) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py”,第 303 行,在执行中 return Database.Cursor.execute(自身、查询、参数)`]1
用 Tree 命令检查你的目录:tree
然后运行进行迁移: enter image description here
然后使用 python3 manage.py createsuperuser
命令创建超级用户: