我通过扩展AbstractUser创建了一个自定义用户模型。我现在想重命名我的模型。
Ran进行了迁移,但出现错误
class MyUser(AbstractUser):
is_student = models.BooleanField(default=False)
is_teacher: bool = models.BooleanField(default=False)
username = models.CharField(max_length=10, blank=False, unique=True)
email = models.EmailField('email address', blank=False)
first_name = models.CharField(max_length=50, blank=False)
last_name = models.CharField(max_length=50, blank=False)
MyUser类以前称为User
class TeacherProfile(PersonProfile):
class Meta:
verbose_name_plural = 'Teacher Profiles'
user = models.OneToOneField(MyUser, on_delete=models.CASCADE, null=True, related_name='teacher_profile')
doj = models.DateField("Date of Joining", null=True, blank=False)
photo = models.ImageField(upload_to='teacher/')
我也有一对一的关系
class StudentProfile(PersonProfile):
class Meta:
verbose_name_plural = 'Student Profiles'
YEAR_CHOICES = []
for r in range(1980, datetime.datetime.now().year + 1):
YEAR_CHOICES.append((r, r))
user = models.OneToOneField(MyUser, on_delete=models.CASCADE, null=True, related_name='student_profile')
gr_phone_no = models.CharField("Guardian's Phone No", max_length=10)
yoe = models.IntegerField('year of enrollment', choices=YEAR_CHOICES,
default=datetime.datetime.now().year)
photo = models.ImageField(upload_to='student/%Y/')
我迁移时遇到此错误
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'main.myuser', but app 'main' doesn't provide model 'myuser'.
The field main.StudentProfile.user was declared with a lazy reference to 'main.myuser', but app 'main' doesn't provide model 'myuser'.
The field main.TeacherProfile.user was declared with a lazy reference to 'main.myuser', but app 'main' doesn't provide model 'myuser'.