我在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
我相信我正在关注instructions related to abstract models mentioned here。
但是,当我运行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。
答案 0 :(得分:5)
您对related_by和last_updated_by的related_name是相同的,不应该是。
我可以看到你的类Meta是好的,只需更改related_name:)