# null value in column "name" violates not-null constraint

Source: https://sqlstreak.com/sql/errors/null-value-violates-not-null-constraint · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** A column declared `NOT NULL` received no value. Provide a value for it, or give the column a `DEFAULT` so inserts can leave it out.

## The exact messages

- PostgreSQL: `ERROR: null value in column "name" of relation "pets" violates not-null constraint`
- SQLite: `NOT NULL constraint failed: pets.name`

## How PostgreSQL prints it

```
ERROR:  null value in column "name" of relation "pets" violates not-null constraint
DETAIL:  Failing row contains (21, null, dog, null, 2, 10.0, f, 2026-01-01).
```

## Why it happens

### Explicitly inserting NULL

Often from application code passing an empty or undefined value.

### Leaving a required column out of the INSERT

Columns you don't list get NULL unless they have a DEFAULT.

## The broken query

```sql
INSERT INTO pets (id, name, species, age, weight_kg, adopted, arrived_on)
VALUES (21, NULL, 'dog', 2, 10, false, '2026-01-01');
```

## The fix

```sql
INSERT INTO pets (id, name, species, age, weight_kg, adopted, arrived_on)
VALUES (21, 'Rex', 'dog', 2, 10, false, '2026-01-01');
SELECT id, name FROM pets WHERE id = 21;
```

Every NOT NULL column now has a value.

| id | name |
| --- | --- |
| 21 | Rex |
