Consider this Django model field:
name = models.CharField(max_length=50, blank=True, null=False)
What is the behavior when a form submits an empty string for this field?
Think about what blank and null control separately: form validation vs database storage.
blank=True allows the form to accept empty input. null=False means the database column cannot store NULL, so empty strings ('') are stored instead.
Choose the correct Django model field declaration that sets a default value of 'guest' for a username field.
Remember that default values for CharField must be strings.
Option B correctly sets the default to the string 'guest'. Option B is invalid because guest is not quoted. Option B sets default to empty string, not 'guest'. Option B sets default to None which is invalid for CharField unless null=True.
Given this model field:
description = models.TextField(null=True, blank=True)
If a form submits no input for description, what value is stored in the database?
Consider how null and blank affect database storage and form validation separately.
blank=True allows the form to accept empty input. null=True allows the database to store NULL explicitly (e.g., field=None). When a form submits no input, the field value is None, so NULL is stored in the database. Django does not automatically convert empty strings ('') to NULL on string-based fields, but if the form submits None, NULL is stored.
Examine this Django model field:
email = models.EmailField(max_length=100, null=True, blank=False)
When submitting a form with an empty email, a validation error occurs. Why?
Think about what blank controls in form validation.
blank=False means the form field is required and cannot be empty. null=True only affects database storage, not form validation.
Consider this field:
title = models.CharField(max_length=5, default='HelloWorld')
What happens when this model is saved without specifying title?
Think about Django's validation process before saving a model.
Django validates field values against max_length before saving. Since the default string 'HelloWorld' is longer than 5 characters, a validation error is raised.