Group
  • Database

    Fix null vs. empty value handling

    Standardizes when fields are null, empty string, or absent so reads stop breaking on inconsistent emptiness.

    • Improve quality
    • Debug & fix
    • Beginner
    • General

Free Prompt

Standardize how my app represents empty values. Find where the same conceptual field is stored inconsistently: sometimes null, sometimes empty string, sometimes the key missing entirely. Profile fields, optional settings, and form-submitted values are the usual offenders. Pick one convention per field type and enforce it: optional text fields are null when unset (not ''); arrays are empty arrays, never null, where the app expects to iterate; booleans are true/false with null only if 'unknown' is a real third state; numbers are null when unset, never 0 unless 0 is the true value. Normalize existing rows with a migration, normalize at the write boundary going forward (form submissions are where empty strings sneak in), and update reads to rely on the convention instead of defensive checks scattered everywhere. Don't change what values mean; a user's intentionally-empty bio and an unset bio can stay distinct if the product treats them differently, but then document the distinction in the schema. Don't blanket-convert 0 to null in numeric fields; 0 is often real data. Deliver: the convention per field type, the normalization migration, the write-boundary normalization, and verification: write and read each optional field in its empty state and confirm one consistent representation.

What This Does / How This Helps

Makes 'empty' mean one thing per field, so your code stops growing defensive checks and your queries stop missing rows. Inconsistent emptiness causes real bugs: a filter for null misses empty strings, a template shows 'null' or a blank where a default should be, a count includes rows that should be excluded. It's the kind of data bug that produces a dozen small mysteries instead of one big error. The migration plus the write-boundary fix stops the bleeding permanently instead of patching each symptom.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts