开发者

Django - Abstract Base Class Model Breaking syncdb

I have this in my 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

I believe I am following the instructions related to abstract models mentioned here.

However I'm getting this error when I run 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开发者_如何学C 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'.   

I'm on Django 1.2.


Your related_name for created_by and last_updated_by are the same and should not be.

for what I can see your class Meta is ok, just change the related_name :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜