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

时间:2015-01-04 02:20:43

标签: 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/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

我在其他地方(here)和(here)读到这是一个“语言环境”问题,但我理解这是一个OSX错误而且我在流浪汉虚拟机上。 ..?

4 个答案:

答案 0 :(得分:3)

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

python manage.py createsuperuser --username thisismyusername

答案 1 :(得分:1)

我遇到了同样的问题,在迁移更改后,我能够创建超级用户。

试试这个:

python manage.py makemigrations

python manage.py migrate

python manage.py createsuperuser

答案 2 :(得分:0)

仅因为您在创建模型后未应用迁移。 所以运行

python manage.py makemigrations然后 python manage.py migrate

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

创建超级用户

python manage.py createsuperuser

答案 3 :(得分:0)

使用 SQL Lite 我删除了数据库文件并运行命令:

python manage.py migrate
python manage.py makemigrations