相关疑难解决方法(0)

具有unique_together的Django多态模型

假设我有这些基本模型:

class Trackable(PolymorphicModel):
    uuid = UUIDField(unique=True)
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
Run Code Online (Sandbox Code Playgroud)

儿童模型扩展了它:

class Like(Trackable):
    content = models.ForeignKey(Content, related_name='likes')

    class Meta:
        unique_together = ['content', 'created_by']
Run Code Online (Sandbox Code Playgroud)

当我运行迁移时,它抱怨:

django.db.models.fields.FieldDoesNotExist: Like has no field named u'created_by'
Run Code Online (Sandbox Code Playgroud)

django django-models

7
推荐指数
1
解决办法
1088
查看次数

标签 统计

django ×1

django-models ×1