南自动迁移添加错误的唯一约束

时间:2013-07-26 20:33:07

标签: django django-models django-south

我的一个模型中有以下代码:

channel = models.OneToOneField(Channel, related_name='stories', null=True, blank=True, unique=False)

请参阅unique=False?好吧,当我使用south创建自动迁移时,它想要添加一个唯一约束:

./manage.py schemamigration core --auto
 ~ Changed field channel on core.Story
 + Added unique constraint for ['channel'] on core.Story

给出了什么!?

1 个答案:

答案 0 :(得分:0)

这是Django,而不是南方。 unique的定义中包含OneToOneField。 (您可以在源代码here中看到它。)

如果unique为False,则可以有多个Story具有相同的Channel。这是一个ManyToOne关系,因此您可能希望将其作为ForeignKey字段。