title: NOT NULL constraint failed: core_profile.user_id
body: <p>I have a model named Profile which is created to extend the User auth model. I have created two forms one is UserForm and ProfileForm. In register.html template I show this two forms and wish to save in the database through the user.</p>
  
  <p>But it constantly shows the exception: Integrity Error</p>
  
  <pre><code>NOT NULL constraint failed: core_profile.user_id
  </code></pre>
  
  <p>whenever I try to submit the post filling out all the fields and hit submit button.</p>
  
  <p>Here are my models:</p>
  
  <pre><code>from __future__ import unicode_literals
  
  from django.db import models
  from django.contrib.auth.models import User
  from django.db.models.signals import post_save
  from django.dispatch import receiver
  
  
  class Profile(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      bio = models.TextField(max_length=500, blank=True)
      location = models.CharField(max_length=30, blank=True)
      birth_date = models.DateField(null=True, blank=True)
  
  
  @receiver(post_save, sender=User)
  def update_user_profile(sender, instance, created, **kwargs):
      if created:
          Profile.objects.create(user=instance)
      instance.profile.save()    
  </code></pre>
  
  <p>And here is my view for posting the forms:</p>
  
  <pre><code>from django.contrib.auth.decorators import login_required
  from django.contrib.auth import login, authenticate
  from django.shortcuts import render, redirect
  
  from .forms import SignUpForm, ProfileForm
  
  
  @login_required
  def home(request):
      return render(request, 'home.html')
  
  
  def signup(request):
      if request.method == 'POST':
          user_form = SignUpForm(request.POST)
          profile_form = ProfileForm(request.POST)
          if user_form.is_valid():
              user = user_form.save()
              profile_form.save()
              user.refresh_from_db()  # load the profile instance created by the signal
              user.profile.birth_date = user_form.cleaned_data.get('birth_date')
              user.save()
              raw_password = user_form.cleaned_data.get('password1')
              user = authenticate(username=user.username, password=raw_password)
              login(request, user)
              return redirect('home')
      else:
          user_form = SignUpForm()
          profile_form = ProfileForm()
      return render(request, 'signup.html', {'user_form': user_form, 'profile_form': profile_form})
  </code></pre>
  
  <p>And here are the forms:</p>
  
  <pre><code>from django import forms
  from django.contrib.auth.forms import UserCreationForm
  from django.contrib.auth.models import User
  
  from .models import Profile
  
  
  class SignUpForm(UserCreationForm):
      birth_date = forms.DateField(help_text='Required. Format: YYYY-MM-DD')
  
      class Meta:
          model = User
          fields = ('username', 'password1', 'password2', 'birth_date')
  
  
  class ProfileForm(forms.ModelForm):
      class Meta:
          model = Profile
          fields = ('bio', 'location')
  </code></pre>
  
  <h2>Thank you,</h2>