0

I have a customer model extends django auth.User like:

class CustomerUser(models.Model):
    user = models.OneToOneField(User,
                                related_name='customeruser',
                                on_delete=models.CASCADE)
    secondary_email = models.EmailField(blank=True, unique=True, null=True)
    created_time = models.DateTimeField(
        auto_now_add=True,
        db_index=True
    )

In my setting.py:

SOCIAL_AUTH_USER_MODEL = 'account.models.CustomerUser'

and err msg look like:

ValueError: Invalid model reference 'account.models.CustomerUser'. String model references must be of the form 'app_label.ModelName'.

What should I do that I can craete a customeruser and make it references to auth.User?

madarame
  • 23
  • 2

1 Answers1

0

replace User with settings.AUTH_USER_MODEL and add from django.conf import settings

user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

help

Pavan kumar
  • 478
  • 3
  • 16
  • I do something below in ```accounts/models.py``` ```class CustomerUser(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='customeruser', on_delete=models.CASCADE) secondary_email = models.EmailField(blank=True, unique=True, null=True) created_time = models.DateTimeField( auto_now_add=True, db_index=True )``` – madarame Jun 24 '20 at 18:34
  • in ```settings.py``` ```AUTH_USER_MODEL='auth.User' SOCIAL_AUTH_USER_MODEL = 'account.CustomerUser'``` It work! but when I use github oauth login my web,it said below: ```FieldDoesNotExist at /social-auth/complete/github/ CustomerUser has no field named 'username'``` I think that social-auth should create a instance in table auth.User and a instance in table CustomerUser. but it seems like not do as I think. – madarame Jun 24 '20 at 18:34