我有两个不同的应用程序,它们具有从 AbstractionBaseUser 继承的单独模型,如下所示
# in doctor/models.py
...
class Patient(AbstractBaseUser):
email = models.EmailField(blank=True, unique=True)
phone_number = models.IntegerField(blank=False, unique=True)
USERNAME_FIELD = 'phone_number'
REQUIRED_FIELD = ['phone_number', 'email']
...
# in Patient/models.py
...
class Patient(AbstractBaseUser):
email = models.EmailField(blank=True, unique=True)
phone_number = models.IntegerField(blank=False, unique=True)
USERNAME_FIELD = 'phone_number'
REQUIRED_FIELD = ['phone_number', 'email']
...
两种型号都有不同的领域
# in settings.py
AUTH_USER_MODEL = [
'doctor.Doctor',
'patient.Patient'
]
我试图这样做,但在进行迁移时它告诉我它必须是一个单一的模型
AssertionError: ForeignKey(['doctor.Doctor', 'patient.Patient']) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string 'self'
我阅读了文档,但找不到任何帮助
我该如何解决这个问题以及如何拥有多个 AUTH_USER_MODEL