title: How can one best mark a model field as required in Django?
body: <p>In Django, I would like the ability to mark certain model fields as required at the model (or at least database) level, to make sure that I am specifying them explicitly (i.e. not relying on defaults) when creating objects.</p>
  
  <p>Currently, Django lets you designate a model field as required at the <em>forms</em> level (by specifying <a href="https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.blank" rel="nofollow"><code>blank=False</code></a> in the model).  However, it doesn't seem like there is a similar option to get this behavior at the model or database level.</p>
  
  <p>It does seem like there are various hacks to achieve something similar though.  For example, you can set the <code>default</code> to something that violates a database constraint.  For example, you can do things like:</p>
  
  <pre><code>models.CharField(_('characters'), max_length=4, default=None)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>models.CharField(_('characters'), max_length=4, default="abcdef")
  </code></pre>
  
  <p>The former example works when saving to the database since <code>None</code> violates the default not-null constraint of <code>null=False</code> (raising an <code>IntegrityError</code>).  The latter works because a <code>DataError</code> is raised when saving.  But I don't know if this is guaranteed to work across all databases, etc.</p>
  
  <p>Am I missing something, or is there a better way?</p>