improve the exception message for integrity constraint violations

Created on 1 October 2024, 3 months ago

Problem/Motivation

Because our SQL tables are usually for entities, they usually have a lot of fields, and this means that integrity constraint violations are really hard to read.

For example, consider this:

 in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 45 of /var/www/html/web/core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php).
 [error]  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null: INSERT INTO "users_field_data" ("uid", "langcode", "preferred_langcode", "preferred_admin_langcode", "name", "pass", "mail", "timezone", "status", "created", "changed", "access", "login", "init", "default_langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14); Array
(
    [:db_insert_placeholder_0] => 10
    [:db_insert_placeholder_1] => en
    [:db_insert_placeholder_2] => en
    [:db_insert_placeholder_3] =>
    [:db_insert_placeholder_4] =>
    [:db_insert_placeholder_5] =>
    [:db_insert_placeholder_6] => me@example.com
    [:db_insert_placeholder_7] =>
    [:db_insert_placeholder_8] => 1
    [:db_insert_placeholder_9] => 1727777383
    [:db_insert_placeholder_10] => 1727777383
    [:db_insert_placeholder_11] => 0
    [:db_insert_placeholder_12] => 0
    [:db_insert_placeholder_13] =>
    [:db_insert_placeholder_14] => 1
)

The use of automatic placeholders makes it REALLY hard to look at this and see which values were for which columns.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component

database system

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024