title: NOT NULL constraint failed error on trying to create a register view
body: <p>So I've been trying my hand at Django authentication. I tried to create a register view which implements two models the django.contrib.auth.models.User and one custom model which shares a OneToOne relationship with User.</p>
  
  <p>Here's the relevant code</p>
  
  <p>models.py</p>
  
  <pre><code>from django.db import models
  from django.utils import timezone
  from django.contrib.auth.models import User
  # Create your models here.
  
  class UserProfile(models.Model):
      user = models.OneToOneField(User)
      SapID = models.IntegerField(default=60000000000)
  
      def __str__(self):
          return self.user.username
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.shortcuts import render
  from .forms import UserFormRegister, UserForm
  # Create your views here.
  
  def register(request):
      if request.method == 'POST':
          user_form = UserForm(data = request.POST)
          users_form = UserFormRegister(data = request.POST)
          if user_form.is_valid() and users_form.is_valid():
              user = user_form.save()
              user.set_password(user.password)
              user.save()
              userregister = users_form.save()
              userregister.user = user
              userregister.save()
              return redirect('/#/')
      else:
          user_form = UserForm()
          users_form = UserFormRegister()
      return render(request, 'register.html',{'user_form':user_form, 'users_form':users_form},) 
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>from django import forms
  from django.contrib.auth.models import User
  from .models import UserProfile
  
  class UserForm(forms.ModelForm):
      password = forms.CharField(widget = forms.PasswordInput())
  
      class Meta:
          model = User
          fields=('username','password','email','first_name','last_name',)
  
  class UserFormRegister(forms.ModelForm):
      class Meta:
          model = UserProfile
          fields = ('SapID', )        
  </code></pre>
  
  <p>SapID is a unique id that each user will have.</p>
  
  <p>Now,when I try to register, the user object gets created but the user profile object doesnt. I get an error saying "NOT NULL constraint failed: foo_userprofile.user_id". What am I missing?</p>