The row in table ‘django_admin_log’ with primary key ‘1’ has an invalid foreign key: django_admin_log.user_id contains a value ‘1’ that does no
t have a corresponding value in common_user.id.
下面展示一些 代码片
。
class User(AbstractUser):
gender = (('male', '男'), ('female', '女'))
# 1: 超管 | 1000: 普通管理员 | 2000:学生 | 3000: 老师
id = models.CharField(primary_key=True, max_length=5, auto_created=True, default=1)
usertype = models.PositiveIntegerField()
stuNum = models.CharField(max_length=20, unique=True)
teaNum = models.CharField(max_length=20, unique=True)
gender = models.CharField(max_length=6, choices=gender, verbose_name="性别")
major = models.CharField(max_length=10, verbose_name="专业")
age = models.PositiveIntegerField(verbose_name="年龄", null=True, blank=True)
grade = models.CharField(max_length=5,default="2019级")
REQUIRED_FIELDS = ['usertype']
USERNAME_FIELD = "username"
class Meta: # 设置类别名
verbose_name = '用户'
verbose_name_plural = '用户'
在删除了abstractUser的id之后报错
解决方法:
删除上述代码,再执行make migrations &migrate
再重新添加代码,再执行make migrations &migrate
就可以了