title: How to assign default value to Django model Integerfield, while related FormField is optional?
body: <p>I want to create a Django model Field (IntegerField) with a default value, and also create a <em>form</em> derived from the model, where the field is optional. If it's not set on the form, then when I save the form, I want the default value saved to the DB.</p>
  
  <pre><code># model.py
  class Invoice(models.Model):
      # IntegrityError "Column 'expireDays' cannot be null"
      expireDays = models.PositiveSmallIntegerField(default=1)
  
      # expireDays = *null* in DB
      expireDays = models.PositiveSmallIntegerField(default=1, blank=True, null=True)
  
  # forms.py
  class InvoiceForm(forms.ModelForm):
      # leaving this line out gives invalid form
      expireDays = forms.IntegerField(required=False)
      class Meta:
          model = Invoice
  </code></pre>
  
  <p>(I used only <em>one</em> of the field declaration lines at a time. :)</p>
  
  <p>I'm not even sure that I'm declaring the <em>default</em> value correctly. The only reference I could find to it was in an article on <a href="http://www.b-list.org/weblog/2007/nov/02/handle-choices-right-way/" rel="noreferrer">handling choices</a> by James Bennett. I have yet to find it in the Django docs (I'm using version 1.2 - maybe it's in 1.3?)</p>
  
  <p>Update - I tried setting the field's default value in the MySql database, to no effect. It seems as if, even when the <em>form</em> does not have a value for the field, it goes ahead and assigns <em>null</em> to the DB, over-riding the MySql default value.</p>
  
  <p>Although I am currently just setting a default value in the view that creates the form - I don't really like that, since it puts the responsibility for the field's integrity in the <em>view</em>, not the DB. </p>
  
  <p>The way I would have <em>thought</em> it would work, is that the field could be set, or not, in the form - if set, that value would be written to the DB, and if <em>not</em> set, the DB default would be used. Instead, if not set, the form is writing a <em>null</em> to the DB. So what's the point of having a default value in the ModelField declaration if it's not used? What exactly does it do?</p>