> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/error-codes/mariadb-error-codes-4000-to-4099/e4025.md).

# Error 4025: CONSTRAINT failed for

| Error Code | SQLSTATE | Error                  | Description                          |
| ---------- | -------- | ---------------------- | ------------------------------------ |
| 4025       | 23000    | ER\_CONSTRAINT\_FAILED | CONSTRAINT `%s` failed for `%s`.`%s` |

## Possible Causes and Solutions

A row violates a [CHECK constraint](/docs/server/reference/sql-statements/data-definition/constraint.md#check-constraints) of the table. The message names the constraint. A constraint defined on a column is named after the table and the column, and a constraint defined for the table has its own name:

```
CREATE TABLE ck (qty INT CHECK (qty >= 0), lo INT, hi INT,
  CONSTRAINT range_ok CHECK (lo <= hi), doc JSON);

INSERT INTO ck (qty) VALUES (-1);
ERROR 4025 (23000): CONSTRAINT `ck.qty` failed for `shop`.`ck`

INSERT INTO ck (lo, hi) VALUES (5, 1);
ERROR 4025 (23000): CONSTRAINT `range_ok` failed for `shop`.`ck`
```

A [JSON](/docs/server/reference/data-types/string-data-types/json.md) column has a CHECK constraint `json_valid()` that the server adds, so invalid JSON fails with this error too:

```
INSERT INTO ck (doc) VALUES ('{"a":1');
ERROR 4025 (23000): CONSTRAINT `ck.doc` failed for `shop`.`ck`
```

`ALTER TABLE … ADD CONSTRAINT … CHECK` also fails with this error when existing rows violate the new constraint.

A constraint fails only when its condition is false. A condition that is `NULL`, for example because a column is `NULL`, passes. With `INSERT IGNORE` and `UPDATE IGNORE`, the row is skipped with a warning instead.

To solve the error:

* Find the condition with `SHOW CREATE TABLE`, or in the [Information Schema CHECK\_CONSTRAINTS table](/docs/server/reference/system-tables/information-schema/information-schema-tables/information-schema-check_constraints-table.md), and correct the data.
* Change or drop the constraint if it's wrong, with `ALTER TABLE … DROP CONSTRAINT`.
* To load data that you will check afterward, you can turn the checks off for the session with [check\_constraint\_checks](/docs/server/server-management/variables-and-modes/server-system-variables.md#check_constraint_checks)`=0`. Rows loaded this way aren't checked later.

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}
