在配置完成模型后出现字段冲突-basemodel
来源:7-9 通过migrate生成表和本章小结
Z_wick
2021-05-24
这张basemodel表在哪里的呀?我在users这个app里面写的是Basemodel这张表没有冲突的字段
`courses.Course.teacher: (models.E006) The field ‘teacher’ clashes with the field ‘teacher’ from model ‘users.basemodel’.
courses.CourseResource.course: (models.E006) The field ‘course’ clashes with the field ‘course’ from model ‘users.basemodel’.
courses.Lesson.course: (models.E006) The field ‘course’ clashes with the field ‘course’ from model ‘users.basemodel’.
courses.Video.lesson: (models.E006) The field ‘lesson’ clashes with the field ‘lesson’ from model ‘users.basemodel’.
operations.CourseComments.course: (models.E006) The field ‘course’ clashes with the field ‘course’ from model ‘users.basemodel’.
operations.UserCourse.course: (models.E006) The field ‘course’ clashes with the field ‘course’ from model ‘users.basemodel’.
organizations.CourseOrg.city: (models.E006) The field ‘city’ clashes with the field ‘city’ from model ‘users.basemodel’.
`。
1回答
-
Z_wick
提问者
2021-05-24
重复查询发现是users model的问题 于是拿老师的model代码发现完美解决 大伙们帮我康康我出了啥问题,暂时找不到
#这是我的代码 from datetime import datetime from django.db import models from django.contrib.auth.models import AbstractUser GENDER_CHOICES = ( ("male", "男"), ("female", "女") ) # Create your models here. class BaseModel(models.Model): add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间') class Mate: abstract = True class UserProfile(AbstractUser): nick_name = models.CharField(max_length=50, verbose_name="昵称", default='') birthday = models.DateField(verbose_name="生日", null=True, blank=True) gender = models.CharField(verbose_name="性别", choices=GENDER_CHOICES, max_length=6) address = models.CharField(max_length=100, verbose_name='地址', default='') mobile = models.CharField(max_length=11, verbose_name="手机号码") image = models.ImageField(verbose_name="用户头像", upload_to='head_image/%Y/%m', default="default.jpg") class Meta: verbose_name = '用户信息表' verbose_name_plural = verbose_name def __str__(self): if self.nick_name: return self.nick_name else: return self.username
# 这是老师的代码 from datetime import datetime from django.db import models from django.contrib.auth.models import AbstractUser GENDER_CHOICES = ( ("male", "男"), ("female", "女") ) class BaseModel(models.Model): add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: abstract = True class UserProfile(AbstractUser): nick_name = models.CharField(max_length=50, verbose_name="昵称", default="") birthday = models.DateField(verbose_name="生日", null=True, blank=True) gender = models.CharField(verbose_name="性别", choices=GENDER_CHOICES, max_length=6) address = models.CharField(max_length=100, verbose_name="地址", default="") mobile = models.CharField(max_length=11, verbose_name="手机号码") image = models.ImageField(verbose_name="用户头像", upload_to="head_image/%Y/%m", default="default.jpg") class Meta: verbose_name = "用户信息" verbose_name_plural = verbose_name def __str__(self): if self.nick_name: return self.nick_name else: return self.username
012021-06-03
相似问题