Django - Create user profile on user creation

Just figured it out.

I forgot to add null=True to the rest of UserProfile model fields.

So the accounts.models.UserProfile fields now looks like:

user = models.ForeignKey(User, unique=True)
birth_date = models.DateField(null=True)
genre = models.CharField(max_length=1, choices=GENRE_CHOICES, null=True)
address = models.CharField(max_length=150, null=True)
postal_code_4 = models.PositiveIntegerField(null=True)
postal_code_3 = models.PositiveIntegerField(null=True)
locatity = models.CharField(max_length=30, null=True)
marital_status = models.CharField(max_length=1, choices=MARITAL_STATUS_CHOICES, null=True)
child_amount = models.PositiveSmallIntegerField(null=True)
is_merchant = models.BooleanField(default=False)
store = models.ForeignKey(Store, null=True)

...and everything is working as intended!

Cheers for trying to help Ashray ^^


You shouldn't use:

user = models.ForeignKey(User, unique=True)

Instead use this:

from django.conf import settings
..
user = models.OneToOneField(settings.AUTH_USER_MODEL)