Informix Error -286
-286 Default value of the primary key column column-name is NULL.
A column that is part of a primary key cannot have null as its default value.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-286 is a clear, well-defined restriction: a column that's part of a primary key can never have
NULL as its default value — this follows directly from what a primary key means (every row
must have a real, non-null value for it).
- Explicitly setting a
NULLdefault value on a primary key column — the direct cause. - A generic table-definition template or schema-generation script that sets a
NULLdefault uniformly across all columns, without excluding primary key columns specifically. - A schema ported from another system with different primary-key/default-value rules.
- Confusion between "no default specified" (fine) and "default explicitly set to
NULL" (not allowed for primary key columns) — these are different things, and only the latter triggers this error.
Solutions / Resolution
- Don't set a
NULLdefault value for a primary key column — either omit theDEFAULTclause entirely, or specify a genuine non-null default if one is actually needed. - Review schema-generation templates or scripts to exclude primary key columns from any
uniform "default to
NULL" logic. - For
SERIAL/SERIAL8/BIGSERIALprimary keys, the auto-generated value already serves as the effective default — don't attempt to also specify an explicitNULLdefault on top of that.
Examples
The disallowed default
CREATE TABLE orders
(
order_id INTEGER DEFAULT NULL,
PRIMARY KEY (order_id)
);
-- -286: order_id is part of the primary key and can't default to NULL
Fix — omit the default entirely, or use a genuine non-null value:
CREATE TABLE orders
(
order_id INTEGER,
PRIMARY KEY (order_id)
);
A generic template mistakenly applying NULL defaults everywhere
-- A schema-generation tool defaults every column to NULL uniformly,
-- including the primary key column
CREATE TABLE customer (id INTEGER DEFAULT NULL, name VARCHAR(50) DEFAULT NULL, PRIMARY KEY (id));
-- -286
Excluding primary key columns from the tool's default-value logic resolves this.
Diagnostic Checks
- Review the column or table definition for a
DEFAULT NULLclause specifically on a primary key column.
Related Errors / Related Topics
- -269 — "Cannot add column column-name that does not accept nulls." Another column-default/constraint restriction in the same general category.
- -100 — "ISAM error: duplicate value for a record with unique key." Related through the same general primary-key/uniqueness family.
Simply remove the NULL default from the primary key column — there's no legitimate use case
for it, since a primary key can never actually hold a null value.