Informix Error -391
-391 Cannot insert a null into column column-name.
This statement tries to put a null value in the noted column. However, that column has been defined as NOT NULL. Roll back the current transaction. If this is a program, review the definition of the table, and change the program logic to not use null values for columns that cannot accept them.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-391 is the most direct, everyday NOT NULL violation: an INSERT (or UPDATE) explicitly
supplies NULL for a column that's declared NOT NULL. Unlike -292 (an implied/omitted
column defaulting to NULL), this is an explicit NULL value provided in the statement itself.
- An
INSERTstatement explicitly passingNULLfor aNOT NULLcolumn — the direct, most common cause. - A parameterized statement/prepared statement binding a
NULLhost variable to aNOT NULLcolumn, often because the application-side value was never actually populated. - An
UPDATEsetting aNOT NULLcolumn toNULLdirectly. - Application logic that doesn't validate required fields before submitting the statement,
letting an unset/empty value pass through as
NULL.
Solutions / Resolution
- Roll back the current transaction, per the official guidance, since the insert/update didn't take effect.
- Modify the application logic to supply a valid non-null value for the column, or ensure required fields are validated before the statement is submitted.
- For parameterized statements, check the host variable's value immediately before binding
it, to catch an unexpectedly
NULLvalue earlier in the code path.
Examples
An explicit NULL rejected
INSERT INTO customers (customer_id, name, email)
VALUES (501, 'Acme Corp', NULL);
-- -391: email is NOT NULL
Fix — supply a valid value:
INSERT INTO customers (customer_id, name, email)
VALUES (501, 'Acme Corp', 'contact@acme.example');
Validating before submitting
-- In application code, validate that required fields are
-- populated before constructing the INSERT/UPDATE statement,
-- rather than relying on the database to catch it after the fact.
Diagnostic Checks
- Check which column the error names and confirm it's declared
NOT NULL. - Trace back to where the value became
NULLin the application logic — an unset variable, a missing form field, a failed upstream lookup, and similar.
Related Errors / Related Topics
- -292 — "An implied insert column column-name does not accept NULLs." The closely related
sibling — an omitted column defaulting to
NULL, rather than an explicitly suppliedNULLvalue. - -386 — "Column contains null values." A related
NOT NULL-enforcement error, at schema alteration time rather than insert/update time.
Trace the NULL value back to its source in the application — this is almost always a missing
or unvalidated required field rather than a database-configuration issue.