E0004 potential-null-violation
Potential NOT NULL violation.
| Code | Name | Category | Default |
|---|---|---|---|
E0004 | potential-null-violation | correctness | error |
What it reports
An INSERT or UPDATE explicitly assigns NULL to a column declared NOT NULL.
Example
UPDATE users SET name = NULL WHERE id = 1;
error[E0004]: Potential NOT NULL violation: column 'name' cannot be assigned NULL
--> q.sql:1:18
|
1 | UPDATE users SET name = NULL WHERE id = 1;
| ^^^^
= help: This column is defined as NOT NULL. Provide a non-NULL value or change the schema constraint.
Fixed:
UPDATE users SET name = 'Anonymous' WHERE id = 1;
Notes
Only a literal NULL is reported; sqlsift doesn't track whether other expressions can be null. A table with a BEFORE INSERT / BEFORE UPDATE trigger in the schema isn't checked for that statement: the trigger may replace the NULL.
Configuring
# sqlsift.toml
[rules]
potential-null-violation = "warn" # or "off"
Or for a single line: -- sqlsift:disable E0004. The examples use the schema on the Rules page.