0Pricing
Django Academy · Lesson

Field Options: null, blank, default

Control what values a column accepts.

Field Options: null, blank, default is a free Django Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Tune Each Field

Beyond the type, every field accepts options that control what values it will accept and how it behaves.

null Is About the Database

The null option decides whether the database column may store NULL. With null=True, the column can be empty in the database.

summary = models.TextField(null=True)

blank Is About Forms

The blank option controls validation, not the database. With blank=True, forms allow the field to be left empty.

summary = models.TextField(blank=True)

null and blank Are Different

Remember the split: null affects the database layer, while blank affects form validation. They solve two separate problems.

Avoid null on Text Fields

For string fields, skip null and just use blank=True. Django prefers an empty string over NULL to keep two empty states from existing.

note = models.CharField(max_length=100, blank=True)

default Supplies a Value

The default option sets the value used when none is given, so new rows start with sensible data.

views = models.IntegerField(default=0)

Callable Defaults

A default can be a callable like timezone.now. Pass the function itself, with no parentheses, so it runs for each new row.

created = models.DateTimeField(default=timezone.now)

unique Prevents Duplicates

Add unique=True and the database refuses two rows with the same value, perfect for usernames or slugs. 🚫

username = models.CharField(max_length=50, unique=True)

choices Limits the Options

The choices option restricts a field to a fixed set of values and renders a dropdown in forms and the admin.

STATUS = [("d", "Draft"), ("p", "Published")]
status = models.CharField(max_length=1, choices=STATUS)

Options Stack Together

You can combine options freely on one field, like blank=True with default. Stack them to express exactly what you need.

tagline = models.CharField(max_length=120, blank=True, default="")

Changes Need a Migration

Editing an option changes the schema. After tweaking null, default, or unique, run a migration so the database matches.

Quick Check

What is the real difference between null and blank?

Recap: Field Options

You now know that null is database-level, blank is form-level, default seeds values, and unique blocks duplicates. Tune fields with confidence! ✨

Frequently asked questions

Is the “Field Options: null, blank, default” lesson free?

Yes — the full text of “Field Options: null, blank, default” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.

What will I learn in “Field Options: null, blank, default”?

Control what values a column accepts. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Django Academy?

No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Field Options: null, blank, default” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Django Academy lesson?

Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Defining a Model Class
  2. Choosing Field Types
  3. Field Options: null, blank, default
  4. str and the Meta Class
← Back to Django Academy