简体   繁体   中英

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 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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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