在我的Django项目中,我有两个应用程序。每个应用程序都有自己的用户,每个应用程序引用不同的数据库。 App1用户是从django AbstractUser继承的,它是本地django管理的数据库,就像在App2中一样,User是从User继承的,并在外部进行管理。现在,当尝试运行服务器时,出现以下错误。
App1
models.py
from django.contrib.auth.models import AbstractUser
class ApiUser(AbstractUser):
api_key = models.CharField(max_length=100,blank=True, unique=True)
class Meta:
db_table = 'app1_apiuser'
app_label = 'app1'
App2
models.py
from django.contrib.auth.models import User
class MyUser(User):
my_key = models.CharField(blank=True, max_length=255)
class Meta:
db_table = 'app2_myuser'
managed = False
app_label = 'app2'
class Device(models.Model):
created_by = models.ForeignKey(User, on_delete=models.DO_NOTHING)
class Meta:
db_table = 'app2_device'
managed = False
settings.py
AUTH_USER_MODEL = 'app1.ApiUser'
错误
app1.ApiUser.groups: (fields.E304) Reverse accessor for 'ApiUser.groups' clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for 'ApiUser.groups' or 'User.groups'.
app1.ApiUser.user_permissions: (fields.E304) Reverse accessor for 'ApiUser.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'ApiUser.user_permissions' or 'User.user_permissions'.
app2.Device.created_by: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.
app2.MyUser.user_ptr: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.