title: Cannot create Django user due to UserProfile creation throwing IntegrityError
body: <p>Django is giving me an integrity error when creating users. From my models.py:</p>
  
  <pre><code>class UserProfile(models.Model):
      user = models.OneToOneField(User)
  
      age = models.DateField()
      city = models.CharField(max_length=30)
      state = models.CharField(max_length=20)
      country = models.CharField(max_length=30)
      primary_language = models.CharField(max_length=30)
      secondary_language = models.CharField(max_length=30, blank=True, null=True)
      tertiary_language = models.CharField(max_length=30, blank=True, null=True)
  
  def create_user_profile(sender, instance, created, **kwargs):
      if created:
          UserProfile.objects.create(user=instance)
  
  post_save.connect(create_user_profile, sender=User)
  </code></pre>
  
  <p>The above code is directly from the Django <a href="https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users" rel="nofollow">site</a>. On to the views.py, where I create the user:</p>
  
  <pre><code>def create_user_and_profile(request):
      form = RegistrationForm(request.POST)
      if form.is_valid():
          # User is saved to DB here
          user = User.objects.create_user( 
              username = form.cleaned_data['username'],
              password = form.cleaned_data['password1'],
              email = form.cleaned_data['email']
          )
          user.first_name = form.cleaned_data['first_name']
          user.last_name = form.cleaned_data['last_name']
          user.save()
          # TODO remaining user creation code goes here
          profile = user.get_profile()
  
          profile.age = form.cleaned_data['age'],
          profile.city = form.cleaned_data['city'],
          profile.state = form.cleaned_data['state'],
          profile.country = form.cleaned_data['country'],
          profile.primary_language = form.cleaned_data['primary_language'],
          profile.secondary_language = form.cleaned_data['secondary_language'],
          profile.tertiary_language = form.cleaned_data['tertiary_language']
          profile.save()
          return user
      else:
          variables = RequestContext(request, {'form': form})
          return render_to_response('registration/register.html', variables)
  </code></pre>
  
  <p>Django will create the user object (as a result of User.objects.create_user) and then blow up. I even tried this in the shell after importing my model file - still blows up. Here is the error that is being thrown:</p>
  
  <p>IntegrityError at /my_url/</p>
  
  <p>myApp_userprofile.age may not be NULL</p>
  
  <p>What I THINK is occurring is that when Django saves the user object, due to the callback it created the UserProfile obj as well. Since it has no data to create the UserProfile with, it throws the integrity error due to attempting to create a database record with NULL as inputs.</p>
  
  <p>Disclosure: I am using sqlite3 and have deleted and added tables multiple times as I have refined my schema. However, as best I can tell, the DB is correct - I walked through each of the tables by hand. </p>
  
  <p>I cannot find a single example of this occurring anywhere else. Why would Django give me the option to create a UserProfile that violates DB constraints with it's very creation? I have been pulling my hair out over this for the last two days and would greatly appreciate any insight. THANKS!</p>
  
  <p>EDIT: Just dropped the DB in order to start from scratch. syncdb throws the SAME ERROR upon creation of my superuser account. What the hell is going on?</p>