Django抽象用户错误 [英] Django Abstract User Error

查看:141
本文介绍了Django抽象用户错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据文档扩展User类,其代码如下:

I am working on extending the User class based on the docs with the code below:

from django.contrib.auth.models import AbstractUser

class MyUser(AbstractUser):
  some_extra_data = models.CharField(max_length=100, blank=True)

但是,我返回以下错误

Reverse accessor for 'User.groups' clashes with reverse accessor for 'MyUser.groups'.
HINT: Add or change a related_name argument to the definition for 'User.groups' or 'MyUser.groups'.


$ b在这种情况下,我该如何解决?

I understand resolving this type of conflict by adding a related_name to FK. How would I resolve it in this scenario?

推荐答案

您需要将AUTH_USER_MODEL设置设置为指向您的MyUser模型, Django知道不要初始化默认模型。请参阅文档

You need to set your AUTH_USER_MODEL setting to point to your MyUser model, so that Django knows not to initialise the default model. See the documentation.

这篇关于Django抽象用户错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆