ProgrammingError:列多次指定

时间:2014-08-09 19:02:47

标签: django django-models

我试图运行' syncdb -all'在我的django项目中,刚刚添加了这个模型。

但是我收到此错误消息:

django.db.utils.ProgrammingError: column "target_content_type_id" specified more than once

为什么会发生这种情况,因为' target_content_type_id'没有重复,也没有在任何其他模型中?

class Action(models.Model):
    actor = models.ForeignKey(User)
    verb = models.CharField(max_length=500)
    action_object_content_type = models.ForeignKey(
        ContentType, related_name='action_object', blank=True, null=True
    )
    action_object_object_id = models.CharField(
        max_length=500, blank=True, null=True
    )
    action_object = generic.GenericForeignKey(
        'action_object_content_type', 'action_object_object_id'
    )
    target_content_type = models.ForeignKey(
        ContentType, related_name='target', blank=True, null=True
    )
    target_content_type_id = models.CharField(
        max_length=500, blank=True, null=True
    )
    target = generic.GenericForeignKey(
        'target_content_type', 'target_content_type_id'
    )

    public = models.BooleanField(default=True)
    timestamp = models.DateTimeField(auto_now_add=True)

1 个答案:

答案 0 :(得分:2)

当您指定ForeignKey字段时,Django会将"_id"附加到字段名称以创建其数据库列名。

在这种情况下,您的target_content_type字段ForeignKey将对应于与您的字段冲突的数据库列target_content_type_id

target_content_type_id重命名为target_content_type_object_id或其他类似内容。

以下是documentation of ForeignKey及更多specifically on Database Representation

相关问题