Updated: 9 November 2026 · Applies to: MariaDB 11.8 and MySQL 8.4 (tested), PHP 8.3 PDO, WHMCS 9 with the Virtualizor module

SQLSTATE[23000] means the database refused to write a row because it would break one of the table’s rules: a NOT NULL column got NULL (error 1048), a unique value already exists (1062), or a foreign key points to a row that is missing (1452) or still in use (1451). The number after “Integrity constraint violation:” tells you which rule it is. The fix is almost always to correct the data your application sends, not to remove the constraint.

How to read the message

PHP applications that use PDO (WordPress plugins, Laravel, WHMCS) print the SQLSTATE first, then the MySQL or MariaDB error number and text. This is the real message we got from PHP 8.3 PDO against MariaDB 11.8 when a script inserted NULL into a NOT NULL column:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fieldid' cannot be null
SQLSTATE: 23000, driver code: 1048

Three parts matter:

  • 23000: the class. Every integrity error in MySQL and MariaDB shares it.
  • 1048: the exact error, which decides the fix (list below).
  • Column, key or constraint name: where to look. If the message also shows the full SQL statement (Laravel-based software, including WHMCS, adds it in brackets after SQL:), it shows which value was wrong.

In code, read the driver error number from $e->errorInfo[1]; $e->getCode() only gives you 23000. A message with SQLSTATE 42000 and error 1064 is a syntax problem instead: see MySQL error 1064.

The common 23000 errors and how to fix each one

All output below comes from a test database on MariaDB 11.8 (and MySQL 8.4 where it differs), with a customers table (unique email) and an orders table whose customer_id must point to a customer.

1048: Column cannot be null

ERROR 1048 (23000) at line 1: Column 'email' cannot be null

The INSERT or UPDATE sent NULL for a column defined as NOT NULL. Usually a form field was empty, a variable was not set, or a lookup that should return an ID returned nothing. Fix it in this order:

  1. Find the column in the message and check why your code had no value for it (log the query or the bound parameters).
  2. Send a real value. If the column really is optional, give it a default or allow NULL:
    ALTER TABLE customers MODIFY phone VARCHAR(30) NULL;
  3. Do not “fix” 1048 by turning off strict mode. We tested this: with an empty sql_mode, a single-row insert of NULL still fails with 1048, and in a multi-row insert MariaDB silently stores an empty string instead and only raises a warning. That hides the bug and leaves bad rows behind. See disable MySQL strict mode only if old software truly needs it.

1062: Duplicate entry for key

ERROR 1062 (23000) at line 1: Duplicate entry 'alice@example.com' for key 'email'

MySQL 8.4 names the key with its table: for key 'customers.email'. The value already exists in a PRIMARY KEY or UNIQUE column. Check for the existing row first:

SELECT id, email FROM customers WHERE email = 'alice@example.com';

Then decide what should happen. To update the existing row instead, use INSERT ... ON DUPLICATE KEY UPDATE. To skip duplicates on purpose (imports), INSERT IGNORE turns the error into a warning:

INSERT IGNORE INTO customers (email) VALUES ('bob@example.com');
SHOW WARNINGS;

Output:

+---------+------+---------------------------------------------------+
| Level   | Code | Message                                           |
+---------+------+---------------------------------------------------+
| Warning | 1062 | Duplicate entry 'bob@example.com' for key 'email' |
+---------+------+---------------------------------------------------+

1452: Cannot add or update a child row

ERROR 1452 (23000) at line 1: Cannot add or update a child row: a foreign key constraint fails (`shop`.`orders`, CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`))

The new row points to a parent that does not exist (here customer 99). Create the parent first, or correct the ID. When you import data table by table, load the parent tables first.

1451: Cannot delete or update a parent row

ERROR 1451 (23000) at line 1: Cannot delete or update a parent row: a foreign key constraint fails (`shop`.`orders`, CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`))

Other rows still use the row you are deleting. Delete or move the child rows first, or, if that is what the application wants, recreate the foreign key with ON DELETE CASCADE or ON DELETE SET NULL. To see which tables point to a table:

SELECT TABLE_NAME, CONSTRAINT_NAME, REFERENCED_TABLE_NAME
FROM information_schema.REFERENTIAL_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = 'shop';

CHECK constraint failed (4025 or 3819)

MariaDB reports a failed CHECK rule with SQLSTATE 23000:

ERROR 4025 (23000) at line 1: CONSTRAINT `orders.qty` failed for `shop`.`orders`

MySQL 8.4 reports the same problem as error 3819 with SQLSTATE HY000, so code that only catches 23000 misses it there:

ERROR 3819 (HY000) at line 1: Check constraint 'orders_chk_1' is violated.

Run SHOW CREATE TABLE orders; to read the rule, and send a value that meets it.

Cardinality violation (SQLSTATE 21000)

This is a different class that people often search for alongside 23000. It means a subquery returned the wrong shape:

ERROR 1242 (21000) at line 1: Subquery returns more than 1 row
ERROR 1241 (21000) at line 1: Operand should contain 1 column(s)

For 1242, make the subquery return one row (LIMIT 1, a tighter WHERE) or use IN (...) instead of =. For 1241, select only one column in the subquery. Both came from MySQL 8.4; MariaDB 11.8 gives 1242 the same way but reports a two-column subquery compared with = as error 4078 (“Illegal parameter data types int and row”).

The same errors in PostgreSQL

PostgreSQL splits class 23 into separate codes. According to the PostgreSQL 18 documentation: 23502 not_null_violation (the “null value in column ... violates not-null constraint” message), 23505 unique_violation, 23503 foreign_key_violation and 23514 check_violation. The fixes are the same as above.

WHMCS: Column fieldid cannot be null when accepting a Virtualizor order

In WHMCS, accepting or provisioning a Virtualizor VPS order can stop with SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fieldid' cannot be null, followed by an insert into tblcustomfieldsvalues. The module tries to save a value (such as the new VPS ID) into a product custom field that does not exist on that product, so WHMCS has no field ID to store it under.

  1. Go to Configuration > System Settings > Products/Services and edit the VPS product.
  2. Open the Custom Fields tab and add the field the Virtualizor module needs, spelled exactly as in the module’s documentation. Make it Admin Only if customers should not see it.
  3. Save, then accept the order or run the Create module command again.
  4. If several products use the module, check each one: custom fields belong to a single product.

Official documentation: MariaDB error code reference, MySQL 8.4 server error reference, INSERT ... ON DUPLICATE KEY UPDATE, PostgreSQL error codes and WHMCS product configuration options.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket