DjangoでのAttributeError: type object 'UserAccount' has no attribute 'USERNAME_FIELD'

現在、チャットルームのようなアプリを作成しており、その開発途中でpython manage.py makemigrationsを行うとエラーが発生してしまいます。学び始めたばかりでどこをどう直せばよいのか分からず苦戦しています。何卒ご指導のほどよろしくお願いします。
エラーとコードの内容は以下の通りです。

発生している問題・エラーメッセージ

エラーメッセージ > AttributeError: type object 'UserAccount' has no attribute 'USERNAME_FIELD' ### 該当のソースコード ```python3.10 from django.db import models from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager class UserManager(BaseUserManager): def create_user(self, email, name, password=None): if not email: raise ValueError('Users must have an email') email = self.normalize_email(email) email = email.lower() user = self.model( email=email, name=name ) user.set_password(password) user.save(using=self._db) return user def create_superuser(self, email, name, password=None): user = self.create_user(email, name, password) user.is_superuser = True user.is_staff = True user.save(using=self._db) return user class UserAccount(AbstractBaseUser, PermissionsMixin): email = models.EmailField("メールアドレス", max_length=255, unique=True) name = models.CharField("名前", max_length=255) customer_id = models.CharField("顧客ID", max_length=255, blank=True, null=True) current_period_end = models.DateTimeField("有効期限", blank=True, null=True) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) objects = UserManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['name'] def __str__(self): return self.email

コメントを投稿

0 コメント