我最近尝试创建两个继承自Rating
的独立模型,但在迁移时我收到了标题中提到的错误。我认为这是由于恶意迁移,因为我的代码中似乎没有冲突?我最初有Rating
有两个可选字段Venue
或Band
,但我觉得这是更好的结构。
为了将来参考,在不遇到此类问题的情况下,这样做的理想方法是什么?
class Rating(models.Model, Activity):
created_at = models.DateTimeField(auto_now_add=True, null=True)
author = models.ForeignKey(settings.AUTH_USER_MODEL, null=True)
rating = models.IntegerField(default=0)
description = models.CharField(max_length=200, null=True)
class Meta:
abstract = True
def get_author(self):
if self.author is None:
return "Anonymous"
else:
return self.author
@property
def activity_actor_attr(self):
return self.author
class BandRating(Rating):
band = models.ForeignKey(Band)
def __str__(self):
return str(self.band) + " rating"
class VenueRating(Rating):
venue = models.ForeignKey(Venue)
def __str__(self):
return str(self.venue) + " rating"
答案 0 :(得分:0)
您似乎正在尝试“隐藏”从您继承的Rating.created_at
模型中声明的Activity
字段 - 这在继承非抽象模型时是不可能的。
更多信息: https://docs.djangoproject.com/en/dev/topics/db/models/#field-name-hiding-is-not-permitted