How to properly create User with allauth and custom user model in Django 4.0

Viewed 99

I have a custom User model, subclassed from django AbstractUser:

class User(AbstractUser):
    alias = models.CharField(
        "Alias",
        max_length=50,
        unique=True,
        null=True
    )
    account_uuid = models.UUIDField(blank=True, null=True)


I have installed allauth library, and all the signup/login mechanisms are working fine.

The problem I'm facing is when I want to import Users instances from a different environment.

from apps.users.models import User

user, created = User.objects.update_or_create(
    email=account_info.get('contact').get('email_address'),
    defaults={
        'username': email,
        'account_uuid': account_uuid,
        'alias': alias
    }
)

When a user had logged in previously with a social connector, this update/create raises an Integrity error for a constraint on User/email.

Is there a proper way for creating a User instance so that it wouldn't break any underlying relations created with allauth models?

0 Answers
Related