简体   繁体   English

无法在 Django、Virtualenv 中创建超级用户

[英]Not able to create super user in Django, Virtualenv

I'm trying to create superuser in django but keep getting this error message.我正在尝试在 django 中创建超级用户,但不断收到此错误消息。

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

I tried eclipse custom command first and than I saw some people able to create super user using window command line with virtualenv, so I installed and activated it.我首先尝试了 eclipse 自定义命令,然后我看到有些人能够使用带有 virtualenv 的窗口命令行创建超级用户,所以我安装并激活了它。 However till now I wasn't able to create superuser.但是直到现在我无法创建超级用户。 What I've been typing in the cmd is我一直在 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

I tried this too.我也试过这个。

C:\Users\name>python manage.py createsuperuser
python: can't open file 'manage.py': [Errno 2] No such file or directory

The command to create a superuser from terminal is,从终端创建超级用户的命令是,

python manage.py createsuperuser

But you have to run this command from the django project directory.但是你必须从 django 项目目录运行这个命令。 The fact that manage.py can't be found means you are not in the project directory.找不到 manage.py 的事实意味着您不在项目目录中。 You have to first cd into it.你必须先cd进去。

you are creating super user inside the python console.您正在 python 控制台中创建超级用户。 don't do like that.不要那样做。 go to the location where manage.py is located via cmd and run the command.通过cmd转到manage.py所在的位置并运行命令。 then you can create the super user.然后你就可以创建超级用户了。

Run this command from your project directory从您的项目目录运行此命令

[projectname]/
├── [appname]/
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

here you should run this from projectname directory.在这里,您应该从 projectname 目录运行它。

use this command :使用这个命令:

python3 manage.py makemigrations

python3 manage.py migrate

python3 manage.py createsuperuser

python manage.py runserver

your error I guess is : [Error `You have 14 unapplied migration(s).我猜您的错误是:[错误`您有 14 个未应用的迁移。 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.运行“python manage.py migrate”以应用它们。

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回溯(最近一次调用):文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py”,第 85 行,在 _execute 返回self.cursor.execute(sql, params) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py”,第303行, 在执行 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 createsuperuser command :然后使用python3 manage.py createsuperuser命令创建超级用户:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM