title: Django: strange IntegrityError upon saving a ModelFormset form
body: <p>I am trying to save a couple ModelFormset forms, but am running into an IntegrityError.  Here is the code:</p>
  
  <pre><code>    billing_formset = BillingFormSet(request.POST,prefix='billing')
      cc_formset = CCFormSet(request.POST,prefix='cc')
  
      if billing_formset.is_valid() and cc_formset.is_valid():
          bp = UserBillingProfile()
          cc = UserCreditCard()
          for form in billing_formset.forms:
              billing_profile = form.save(commit=False)
              billing_profile.user = request.user
              bp = billing_profile.save()
          for form in cc_formset.forms:
              cc = form.save(commit=False)
              cc.billing_profile = bp
              cc = form.save()
  </code></pre>
  
  <p>This code caused the following code:</p>
  
  <blockquote>
    <p>IntegrityError at [url removed]
    (1048, "Column 'user_billing_profile_id' cannot be null")</p>
  </blockquote>
  
  <hr>
  
  <p>EDIT:  Here is some iterative code that also fixes my typo.  I'm running into basically the same problem.</p>
  
  <pre><code>        billing_profile_form = billing_formset.forms[0]
          cc_form = cc_formset.forms[0]
  
          unsaved_billing_profile = billing_profile_form.save(commit=False)
          user_billing_profile = unsaved_billing_profile.save()
  
          unsaved_cc = cc_form.save(commit=False)
          unsaved_cc.user_billing_profile = user_billing_profile
          cc = unsaved_cc.save()
  </code></pre>
  
  <p>Problem line gives:  "Cannot assign None: "UserCreditCard.user_billing_profile" does not allow null values."  It seems unsaved_billing_profile.save() is returning null?  Why?</p>
  
  <hr>
  
  <p>This is kind of crazy; everything seems to be right.  I don't get any errors when saving the billing profile.  Any ideas on what I should check?  Things seem to be going wrong in the second loop, where bp apparently has a value of None.</p>
  
  <p>Thanks in advance.</p>