Когда я пытаюсь создать суперпользователя с помощью команды python manage.py createuperuser, он выдает следующую ошибку:
Username: wcud
Traceback (most recent call last):
File "/home/Music/ENV/lib/python3.5/site-packages/django/db/models/options.py", line 617, in get_field
return self.fields_map[field_name]
KeyError: ''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/Music/ENV/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/Music/ENV/lib/python3.5/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/Music/ENV/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/Music/ENV/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 63, in execute
return super(Command, self).execute(*args, **options)
File "/home/Music/ENV/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/Music/ENV/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 129, in handle
field = self.UserModel._meta.get_field(field_name)
File "/home/Music/ENV/lib/python3.5/site-packages/django/db/models/options.py", line 619, in get_field
raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: User has no field named ''
Я расширяю модель пользователя Django, она работала нормально, но когда я удалил свою базу данных, а затем снова успешно восстановил базу данных, но когда я собираюсь создать суперпользователя, он выдает эту ошибку.
РЕДАКТИРОВАТЬ: Вот код для модели пользователя:
class User(AbstractBaseUser):
username = models.CharField(max_length=64, unique=True, validators=[RegexValidator(regex=USERNAME_REGX, message="Username only contain A-Z,a-z,0-9 or . _ + - $", code="Invalid Username")])
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
blank=True,
null=True,
)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
objects = MyUserManager()
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['']
def __str__(self):
return self.username
def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True
def get_full_name(self):
return self.username
def get_short_name(self):
return self.username
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
phone_regex = RegexValidator(regex=r'^\d{10}$', message="Please Enter Correct Mobile Number...")
phone_number = models.CharField(validators=[phone_regex], max_length=17, blank=False, unique=True)
state = models.CharField(max_length=50, choices=STATES, blank=True, default=STATES[0][0])
#date_of_birth = models.DateTimeField(auto_now=False, blank=True)
balance = models.DecimalField(max_digits=8, decimal_places=2, default=0)
bonus = models.DecimalField(max_digits=4, decimal_places=2, default=25)
widhdrawable_balance = models.DecimalField(max_digits=8, decimal_places=2, default=0)
match_played = models.IntegerField(default=0)
total_wins = models.IntegerField(default=0)
is_email_confirmed = models.BooleanField(default=False)
def __str__(self):
return self.user.username
РЕДАКТИРОВАТЬ 2: Проблема существует, даже если я не восстановлю БД после удаления из БД
Пожалуйста, помогите!