Opened 13 years ago

Closed 13 years ago

#16251 closed Uncategorized (invalid)

Db/Models: distinction btw "null" and "blank"

Reported by: John Chandler Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: john.chandler@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the 1.3 doc (https://docs.djangoproject.com/en/1.3/topics/db/models/), some distinctions are drawn between allowing/disallowing null in the database and allowing/disallowing blank on data-entry:

====
null

If True, Django will store empty values as NULL in the
database. Default is False.

blank

If True, the field is allowed to be blank. Default is False.

Note that this is different than null. null is purely
database-related, whereas blank is validation-related. If a field
has blank=True, validation on Django's admin site will allow entry
of an empty value. If a field has blank=False, the field will be
required.

====

This leaves me, and I suspect at least some other newbies, wondering what happens if 1. blank is allowed on data-entry, 2. null is not allowed in the database, and 3. a user leaves a field blank. Is the input rejected? Is a default, non-null value inserted? Are developers advised not to allow conditions 1. and 2. both to apply in the same instance?

It occurs to me that this might have been intentionally "left as an exercise for the reader," but I'd suggest that approach would be more correct in the tutorial than in the ref.

Change History (2)

comment:1 by John Chandler, 13 years ago

Cc: john.chandler@… added

comment:2 by Aymeric Augustin, 13 years ago

Resolution: invalid
Status: newclosed

The document you're referring to is just a summary:

[The options are] fully explained in the reference, but here's a quick summary of the most often-used ones


Your question is actually about the behavior of null, and the detailed answer is in the reference: https://docs.djangoproject.com/en/1.3/ref/models/fields/#null

If this explanation is still not sufficiently clear, could you reopen the ticket?

Note: See TracTickets for help on using tickets.
Back to Top