Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>null=True</code> sets <code>NULL</code> (versus <code>NOT NULL</code>) on the column in your DB. Blank values for Django field types such as <code>DateTimeField</code> or <code>ForeignKey</code> will be stored as <code>NULL</code> in the DB.</p> <p><code>blank=True</code> determines whether the field will be required in forms. This includes the admin and your own custom forms. If <code>blank=True</code> then the field will not be required, whereas if it's <code>False</code> the field cannot be blank.</p> <p>The combo of the two is so frequent because typically if you're going to allow a field to be blank in your form, you're going to also need your database to allow <code>NULL</code> values for that field. The exception is <code>CharField</code>s and <code>TextField</code>s, which in Django are <em>never</em> saved as <code>NULL</code>. Blank values are stored in the DB as an empty string (<code>''</code>).</p> <p>A few examples:</p> <pre><code>models.DateTimeField(blank=True) # raises IntegrityError if blank models.DateTimeField(null=True) # NULL allowed, but must be filled out in a form </code></pre> <p>Obviously those two options don't make logical sense to use (though, there might be a use case for <code>null=True, blank=False</code> if you want a field to always be required in forms, but optional when dealing with an object through something like the shell.)</p> <pre><code>models.CharField(blank=True) # No problem, blank is stored as '' models.CharField(null=True) # NULL allowed, but will never be set as NULL </code></pre> <p><code>CHAR</code> and <code>TEXT</code> types are never saved as <code>NULL</code> by Django, so <code>null=True</code> is unnecessary. However, you can manually set one of these fields to <code>None</code> to force set it as <code>NULL</code>. If you have a scenario where that might be necessary, you should still include <code>null=True</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload