Python 在Django中创建超级用户时出错

Python 在Django中创建超级用户时出错,python,django,command-line,django-admin,Python,Django,Command Line,Django Admin,我正在尝试创建一个超级用户来访问我的应用程序中的Django管理框架。我正在Windows 8.1计算机上使用Vagrant: > ./manage.py createsuperuser 但是,我得到以下错误: Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/va

我正在尝试创建一个超级用户来访问我的应用程序中的Django管理框架。我正在Windows 8.1计算机上使用Vagrant:

> ./manage.py createsuperuser
但是,我得到以下错误:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, i
n execute_from_command_line
    utility.execute()
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, i
n execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in ru
n_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in ex
ecute
    output = self.handle(*args, **options)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsu
peruser.py", line 141, in handle
    self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
  File "/vagrant/myapp/accounts/managers.py", line 52, in create_superuser
    return self._create_user(email, password, True, True, **extra_fields)
  File "/vagrant/myapp/accounts/managers.py", line 31, in _create_user
    user.set_slug()
  File "/vagrant/myapp/accounts/models.py", line 164, in set_slug
    slug = slugify(self.username, max_length=50).lower()
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/slugify/main.py", line 101, in slugify
    text = join_words(words, separator, max_length)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/slugify/main.py", line 78, in join_words
    text = next(words)    # text = words.pop(0)
StopIteration
回溯(最近一次呼叫最后一次):
文件“/manage.py”,第10行,在
从命令行(sys.argv)执行命令
文件“/home/vagrant/Envs/myapp/local/lib/python2.7/site packages/django/core/management/_init__.py”,第399行,i
n从命令行执行命令
utility.execute()
文件“/home/vagrant/Envs/myapp/local/lib/python2.7/site packages/django/core/management/_init__.py”,第392行,i
执行
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/home/vagrant/Envs/myapp/local/lib/python2.7/site packages/django/core/management/base.py”,第242行,ru格式
n_来自_argv
self.execute(*args,**选项._dict__;
文件“/home/vagrant/Envs/myapp/local/lib/python2.7/site packages/django/core/management/base.py”,第285行,在ex
埃克特
输出=self.handle(*args,**选项)
文件“/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsu
peruser.py“,第141行,手柄中
self.UserModel.\u default\u manager.db\u manager(数据库).创建超级用户(**用户数据)
文件“/vagrant/myapp/accounts/managers.py”,第52行,创建超级用户
返回self.\u创建用户(电子邮件、密码、True、True、**额外字段)
文件“/vagrant/myapp/accounts/managers.py”,第31行,在创建用户
user.set_slug()
文件“/vagrant/myapp/accounts/models.py”,第164行,在set_段塞中
slug=slugify(self.username,最大长度=50)
文件“/home/vagrant/Envs/myapp/local/lib/python2.7/site packages/slugify/main.py”,第101行,在slugify中
text=连接词(词、分隔符、最大长度)
文件“/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/slugify/main.py”,第78行,用join_字表示
text=next(words)#text=words.pop(0)
停止迭代
我在别处()和()读到过这是一个“区域设置”问题,但我的理解是这是一个OSX错误,我在一个流浪的虚拟机上

使用
--username
标志,而不是直接传递用户名:

python manage.py createsuperuser --username thisismyusername
使用
--username
标志,而不是直接传递用户名:

python manage.py createsuperuser --username thisismyusername
系统将尝试同步并询问:

You have installed Django's auth system, and don't have any superusers                  defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'yogesh'): 
Email address: yogesh.gupta38@gmail.com
Password: 
Password (again): 
Superuser created successfully.
我也面临着同样的问题,这些东西在我的案例中起了作用

系统将尝试同步并询问:

You have installed Django's auth system, and don't have any superusers                  defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'yogesh'): 
Email address: yogesh.gupta38@gmail.com
Password: 
Password (again): 
Superuser created successfully.

我也遇到了同样的问题,这个东西在我的情况下也起了作用。

在迁移更改后,我能够创建超级用户

试试这个:

python manage.py makemigrations

python manage.py migrate

python manage.py createsuperuser

我也面临同样的问题,在迁移更改后,我能够创建超级用户

试试这个:

python manage.py makemigrations

python manage.py migrate

python manage.py createsuperuser

只是因为您在创建模型后没有应用迁移。 快跑

python manage.py makemigrations
然后
python manage.py迁移

现在已经应用了迁移,您可以通过运行


python manage.py createsuperuser

仅仅因为您在创建模型后没有应用迁移。 快跑

python manage.py makemigrations
然后
python manage.py迁移

现在已经应用了迁移,您可以通过运行


python manage.py createsuperuser

@alias51您运行的完整命令是什么?您是否有自定义用户模型?它是
python manage.py createsuperuser
,然后我按照提示输入电子邮件和密码,并获得上述错误。是的,我有一个自定义用户模型。@alias51您可以发布您的模型吗?@alias51您正在运行的完整命令是什么?您是否有自定义用户模型?它是
python manage.py createsuperuser
,然后我按照提示输入电子邮件和密码,并获得上述错误。是的,我有一个自定义的用户模型。@你能发布你的模型吗?