'Make already existing Django-user model case-insensitve

So right now I have

class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_('E-mail'), unique=True)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(default=timezone.now)
    wants_email = models.BooleanField(_("Send mig emails"),default=True)
    is_active  = models.BooleanField(default=True)
    is_staff   = models.BooleanField(default=False)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email

which works great by using email as login. The issue is that the e-mail is case sensitive i.e [email protected] is can not login as [email protected].

I have seen several ways of creating case insensitive username in models (some suggest just cast the user-name to lower when entered where some suggest its a bad idea), but I don't know if I can do that now, since I have users in my database with like [email protected].



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source