繁体   English   中英

Django - 抽象基类模型打破syncdb

[英]Django - Abstract Base Class Model Breaking syncdb

我在models.py中有这个:

class AuditableTable(models.Model):
    class Meta:
        abstract = True
        created_by = models.ForeignKey(User,blank=True,
        related_name="%(app_label)s_%(class)s_related1")
        last_updated_by = models.ForeignKey(User,blank=True,
        related_name="%(app_label)s_%(class)s_related1")

class Company(AuditableTable): pass

我相信我遵循与此处提到的抽象模型相关说明

但是,当我运行manage.py syncdb时,我收到此错误:

Error: One or more models did not validate:
ItemLocator.company: Accessor for field 'created_by' clashes with related field 'User.itemlocator_company_related1'. Add a related_name argument to the definition for 'created_by'.                                                                                       
ItemLocator.company: Reverse query name for field 'created_by' clashes with related field 'User.itemlocator_company_related1'. Add a related_name argument to the definition for 'created_by'.                                                                             
ItemLocator.company: Accessor for field 'last_updated_by' clashes with related field 'User.itemlocator_company_related1'. Add a related_name argument to the definition for 'last_updated_by'.                                                                             
ItemLocator.company: Reverse query name for field 'last_updated_by' clashes with related field 'User.itemlocator_company_related1'. Add a related_name argument to the definition for 'last_updated_by'.   

我在使用Django 1.2。

您对created_by和last_updated_by的related_name是相同的,不应该是。

因为我可以看到你的类Meta是好的,只需更改related_name :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM