###実現したいこと
Userモデルをmigrateしたい。
エラーの意味だけでも分かったら教えていただきたいです。
###発生しているエラー
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'polls.user', but app 'polls' doesn't provide model 'user'.
以下のUserモデルを追加すると、makemigrationsはできるけれどmigrateができず、上記のエラーが出ます。
上記のエラーで検索すると、migrationファイルを全て消すと動くみたいなことが書かれていたので、アプリケーションを一から作り直しましたがうまくいきませんでした。ちなみにsetttings.pyに
AUTH_USER_MODEL = "polls.User"
は追加しています。
app 'polls' doesn't provide model 'user' の部分が引っかかるのですが、意味だけでも分かったら教えてください。
###該当のソースコード
Python
1# models.py 2class MyUserManager(UserManager): 3 use_in_migrations = True 4 5 def _create_user(self, username, email, password, **extra_fields): 6 if not username: 7 raise ValueError("The given username must be set") 8 email = self.normalize_email(email) 9 username = self.model.normalize_username(username) 10 user = self.model(username=username, email=email, **extra_fields) 11 user.set_password(password) 12 user.save(using=self._db) 13 return user 14 15 def create_user(self, username, email=None, password=None, **extra_fields): 16 extra_fields.setdefault("is_staff", False) 17 extra_fields.setdefault("is_superuser", False) 18 return self._create_user(username, email, password, **extra_fields) 19 20 def create_superuser(self, username, email=None, password=None, **extra_fields): 21 extra_fields.setdefault("is_staff", True) 22 extra_fields.setdefault("is_superuser", True) 23 24 if extra_fields.get("is_staff") is not True: 25 raise ValueError("Superuser must have is_staff=True.") 26 if extra_fields.get("is_superuser") is not True: 27 raise ValueError("Superuser must have is_superuser=True.") 28 29 return self._create_user(username, email, password, **extra_fields) 30 31 32class User(AbstractBaseUser, PermissionsMixin): 33 34 username_validator = UnicodeUsernameValidator() 35 36 username = models.CharField( 37 _("username"), 38 max_length=30, 39 unique=True, 40 default="nanashi", 41 help_text=_( 42 "Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only." 43 ), 44 validators=[username_validator], 45 error_messages={"unique": _("A user with that username already exists."),}, 46 ) 47 first_name = models.CharField(_("first name"), max_length=30,) 48 last_name = models.CharField(_("last name"), max_length=30,) 49 email = models.EmailField(_("email address"), unique=True) 50 51 is_staff = models.BooleanField( 52 _("staff status"), 53 default=False, 54 help_text=_("Designates whether the user can log into this admin site."), 55 ) 56 is_active = models.BooleanField( 57 _("active"), 58 default=True, 59 help_text=_( 60 "Designates whether this user should be treated as active. " 61 "Unselect this instead of deleting accounts." 62 ), 63 ) 64 date_joined = models.DateTimeField(_("date joined"), default=timezone.now) 65 66 objects = MyUserManager() 67 68 EMAIL_FIELD = "email" 69 USERNAME_FIELD = "username" 70 REQUIRED_FIELDS = ["email"] 71 72 class Meta: 73 verbose_name = _("user") 74 verbose_name_plural = _("users") 75 76 def get_full_name(self): 77 full_name = "%s %s" % (self.first_name, self.last_name) 78 return full_name.strip() 79 80 def get_short_name(self): 81 return self.first_name 82 83 def email_user(self, subject, message, from_email=None, **kwargs): 84 send_mail(subject, message, from_email, [self.email], **kwargs)
###バージョン
Django3.0.4
回答1件
あなたの回答
tips
プレビュー