管理者アカウントを作るときにエラーが出ます
usernameを打つところまでは行きますがusernameを打つとエラーが出ます
error
1AttributeError: 'Manager' object has no attribute 'get_by_natural_key'
python
1from django.db import models 2from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager 3from django.contrib.auth.models import PermissionsMixin 4from django.db import models 5from django.utils import timezone 6from django.utils.translation import gettext_lazy as _ 7 8 9class User(AbstractBaseUser, PermissionsMixin): 10 username = models.CharField(max_length=25, unique=True) 11 email = models.EmailField(unique=True) 12 icon = models.ImageField(blank=True, null=True) 13 introduction = models.CharField(max_length=75, blank=True, null=True) 14 followers = models.ManyToManyField('self', blank=True, symmetrical=False) 15 is_staff = models.BooleanField( 16 _('staff status'), 17 default=False, 18 help_text=_('Designates whether the user can log into this admin site.'), 19 ) 20 is_active = models.BooleanField( 21 _('active'), 22 default=True, 23 help_text=_( 24 'Designates whether this user should be treated as active. ' 25 'Unselect this instead of deleting accounts.' 26 ), 27 ) 28 date_joined = models.DateTimeField(default=timezone.now) 29 30 objects = 'UserManager()' 31 32 EMAIL_FIELD = 'email' 33 USERNAME_FIELD = 'username' 34 REQUIRED_FIELDS = ['email'] 35 36 class Meta: 37 verbose_name = _('user') 38 verbose_name_plural = _('users') 39class UserManager(BaseUserManager): 40 41 use_in_migrations = True 42 43 def _create_user(self, username, email, password, **extra_fields): 44 45 if not username: 46 raise ValueError('The given username must be set') 47 48 if not email: 49 raise ValueError('The given email must be set') 50 51 user = self.model(username=self.model.normalize_username(username), email=self.normalize_email(email), **extra_fields) 52 user.set_password(password) 53 user.save(using=self._db) 54 return user 55 56 def create_user(self, username, email=None, password=None, **extra_fields): 57 extra_fields.setdefault('is_staff', False) 58 extra_fields.setdefault('is_superuser', False) 59 return self._create_user(username, email, password, **extra_fields) 60 61 def create_superuser(self, username, email, password, **extra_fields): 62 extra_fields.setdefault('is_staff', True) 63 extra_fields.setdefault('is_superuser', True) 64 65 if extra_fields.get('is_staff') is not True: 66 raise ValueError('Superuser must have is_staff=True') 67 68 if extra_fields.get('is_superuser') is not True: 69 raise ValueError('Superuser must have is_superuser=True') 70 71 return self._create_user(username, email, password, **extra_fields) 72
1. 「管理者アカウントを作るときにエラーが出ます」っとありますが、どういう操作で管理者アカウントを作成しようとしたのでしょうか?
2. 「usernameを打つところまでは行きますがusernameを打つとエラーが出ます」とあります
2-1. usernameを打つところとはどこでしょうか?
2-2. usernameを打つとどこにエラーが出るのでしょうか?
あなたの回答
tips
プレビュー