Why Can a Unique Database Field Still Contain Several Missing Values?
Two imported organizations have no external reference. Both are saved successfully despite a unique constraint on that field. This can be expected database behavior, yet still surprise a team that understood “unique” to mean “every record must have a different identifier.”
Before changing the constraint, distinguish two questions: must an identifier be present, and how should missing identifiers participate in uniqueness?
Write the identity rule first
PostgreSQL's constraint documentation states that unique constraints treat NULL values as distinct by default. NULLS NOT DISTINCT changes that treatment. Other database implementations can differ.
Those choices do not determine the business rule. Several incomplete organizations may legitimately await external references. Alternatively, the external reference may be mandatory before a record enters the operational table.
Write the rule without SQL first. For example: “Within one source system, an external reference identifies exactly one organization; records without a reference remain in staging.”
Test the relevant combinations
Illustrative example: two sources
Suppose Cedar and Birch are separate source systems, and both assign reference A17 to different organizations. A uniqueness rule on reference alone would reject a legitimate combination if identifiers are only unique within their source.
Test a key containing source and reference when that reflects the actual contract. Then test two A17 records from Cedar, two records with no reference, and a record with no source.
Do not infer that a composite key is correct simply because it makes the import pass. The source's documented identity scope must justify it.
Distinguish empty text from missing data
Add an empty string and a string containing spaces. Decide whether the importer normalizes them, rejects them or preserves them. That decision should happen deliberately before uniqueness checks become the accidental cleanup mechanism.
Keep leading zeros when they belong to the identifier. Converting A-like codes into numbers to simplify comparison can create a different identity problem.
Keep staging separate from acceptance
An incomplete record can be useful for investigation without being ready for operational use. A staging area can retain the source row, validation result and missing-field reason.
Avoid assigning a shared placeholder such as “unknown” to every missing identifier. It may create collisions or encourage unrelated entities to be merged.
A generated internal ID can identify the staging row, but it should not be presented as proof that the external organization's identity has been resolved.
Plan for newly discovered collisions
Before adding or changing a unique constraint, inspect existing data. Define how the team will review collisions and distinguish repeated imports from genuinely separate organizations.
Preserve evidence rather than keeping whichever row was encountered first. The correct resolution may involve correcting a source identifier, maintaining separate records, or merging confirmed duplicates through a controlled process.
Do not let the migration invent that decision automatically.
Verify the rule across entry points
Run the same fixture through manual entry, file import and synchronization. A database constraint should not be the only place where the user learns that a required identifier is absent.
Acceptance evidence should show allowed combinations, rejected combinations and a useful explanation for each rejection. Include the database version and configured NULL behavior.
Read why business identifiers often belong in text fields before standardizing the format. The aim is a trustworthy identity contract, not merely a table with no constraint errors.
Editorial note
Prepared with AI assistance. Primary sources and the FutureOS article inventory were checked on October 26, 2026. Examples are illustrative, not customer results. FutureOS is described as being in prelaunch in its current introduction. This guide does not claim an available product feature, integration or service, and no independent expert review is claimed.




Comments