【发布时间】:2010-02-20 21:19:27
【问题描述】:
我有一个模型与另一个模型有多个多对多关系,如下所示:
class Match(models.Model):
"""Model docstring"""
Match_Id = models.AutoField(primary_key=True)
Team_one = models.ManyToManyField('Team',related_name='Team one',symmetrical=False,)
Team_two = models.ManyToManyField('Team',related_name='Team two',symmetrical=False,)
stadium = models.CharField(max_length=255, blank=True)
Start_time = models.DateTimeField(auto_now_add=False, auto_now=False, blank=True, null=True)
Rafree = models.CharField(max_length=255, blank=True)
Judge = models.CharField(max_length=255, blank=True)
winner = models.ForeignKey('Team', related_name='winner',to_field='Team_Name')
updated = models.DateTimeField('update date', auto_now=True )
created = models.DateTimeField('creation date', auto_now_add=True )
实现这样的模型的最佳方法是什么?尽管 django 在传递模型 sql 时不会抛出任何错误,但一旦执行了 syncdb,它就会抛出错误,说 there is no unique constraint matching given keys
【问题讨论】:
标签: python database django django-models