1

我正在尝试在 linux 上使用此命令创建超级用户:

python manage.py createsuperuser

我也试过sudo。它给了我错误。

    Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/commands/createsuperuser.py", line 63, in execute
    return super(Command, self).execute(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/commands/createsuperuser.py", line 183, in handle
    self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py", line 168, in create_superuser
    return self._create_user(username, email, password, **extra_fields)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py", line 149, in _create_user
    user = self.model(username=username, email=email, **extra_fields)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/base_user.py", line 68, in __init__
    super(AbstractBaseUser, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 555, in __init__
    raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'is_staff' is an invalid keyword argument for this function

模型.py

from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import (BaseUserManager, AbstractBaseUser, UserManager,PermissionsMixin)

class User(AbstractBaseUser,PermissionsMixin):
    class Meta:
        db_table = "users"
    username = models.CharField(max_length=50,unique=True)
    email = models.EmailField(unique=True)
    password = models.CharField(max_length=100,default = True)
    is_active = models.BooleanField(default=True)
    objects = UserManager()
    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['email']

class UserDetail(AbstractBaseUser):
    class Meta:
        db_table = "user_details"
    address = models.CharField(max_length=100)
    city = models.CharField(max_length=100)
    state = models.CharField(max_length=100)
    phone = models.CharField(max_length = 100)
    profileImg = models.ImageField(upload_to='images/',blank=True, null=True,default="images/default-profile.jpg")
    gender = models.CharField(max_length= 10,default= True)
    education = models.CharField(max_length=100, default=True)
    HOBBIES = (
        ('Games', 'Games'),
        ('Music', 'Music'),
        ('Dance', 'Dance'),
        ('Reading', 'Reading'),
    )
    hobbies = models.CharField(choices=HOBBIES, max_length=100, blank=True)
    objects = UserManager()
    user = models.ForeignKey(User)
    USERNAME_FIELD = 'city'
    REQUIRED_FIELDS = ['phone']

考虑模型文件,如果有人知道这个问题的解决方案,请告诉我。谢谢

4

0 回答 0