gpt4 book ai didi

python - Django - 抽象基类模型破坏 syncdb

转载 作者:太空狗 更新时间:2023-10-30 02:49:43 28 4
gpt4 key购买 nike

我的 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。

最佳答案

created_by 和 last_updated_by 的 related_name 相同,但不应该相同。

据我所知,您的 class Meta 没问题,只需更改 related_name :)

关于python - Django - 抽象基类模型破坏 syncdb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6986761/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com