Django发生Article.author: (fields.E304) Reverse accessor for 'Article.author'错误

Django发生错误如下:
SystemCheckError: System check identified some issues:

ERRORS:
content.Article.author: (fields.E304) Reverse accessor for ‘Article.author’ clashes with reverse accessor for ‘Article.news_author’.
HINT: Add or change a related_name argument to the definition for ‘Article.author’ or ‘Article.news_author’.
news.Article.news_author: (fields.E304) Reverse accessor for ‘Article.news_author’ clashes with reverse accessor for ‘Article.author’.
HINT: Add or change a related_name argument to the definition for ‘Article.news_author’ or ‘Article.author’.

Django使用两个app创建外键时对‘auth.User’产生了多对多的依赖所以报错。解决方案在网上查到两种其一是:
在setting.py配置文件中加上

AUTH_USER_MODEL = 'users.UserProfile' 其中users:app UserProfile:model

第二种方案是在创建model时使用related_name,内容如下

news_author = models.ForeignKey('auth.User',related_name='news_author', blank=True, null=True,on_delete=models.CASCADE, verbose_name='作者')

我使用的是第二种方法加上related_name后该问题及解决,可以顺利创建数据表并写入数据.
附上查到解决方案的链接stackoverflow查到的相似问题解决方案

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值