django-allauth and django-phone-auth clash on EmailAdress.User mutual accessors

44 views Asked by At

I have my auth app in Django and a custom user defined as

#auth/models.py

class User(AbstractUser):
    pass

And it is set as the user_model in settings:

AUTH_USER_MODEL = 'auth.User'

I'd like to use django-phone-auth for authenticating with phone or email, and django-allauth to authenticate with social providers. After I add the both to my virtual environment and try migrate I get the error:

account.EmailAddress.user: (fields.E304) Reverse accessor 'User.emailaddress_set' for 'account.EmailAddress.user' clashes with reverse accessor for 'phone_auth.EmailAddress.user'.

The problem is in the same-named models having foreign key relation to the user model in the two packages.

#allauth/account/models.py

class EmailAddress(models.Model):
    user = models.ForeignKey(
        allauth_app_settings.USER_MODEL,
        verbose_name=_("user"),
        on_delete=models.CASCADE,
        # 
        # !!!! related_name='accountuser' would solve the conflict
    )
     ...

vs.

#phone-auth/models.py

class EmailAddress(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    ...

The clash is due to reverse reference conflict, and adding related_name='accountuser' to any of the user fields does solve it. But changing original code of installed packages is not a good idea. Can anyone advise how it should be sorted out, please. Many thanks!

0

There are 0 answers