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查到的相似问题解决方案