0

Background

I recently encountered an error when I try to create a new menu item:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default value: INSERT INTO "menu_tree" ("id", "menu_name") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => menu_link_content:83480782-adf3-4c99-82fa-e91ba2885eb5 [:db_insert_placeholder_1] => main ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Other parts of the site appear to be working fine from what I can see, but I simply can not create any new menu links.

Unknown Cause

I do not know what is the cause of this issue, but it occurred shortly after I changed the collation of the tables and columns to utf8mb4_unicode_ci. I had setup the database to use utf8mb4 and utf8mb4_unicode_ci when I created it, but for some reason this only set the database collation, so new tables and columns were using utf8mb4_0900_ai_ci. This resulted in the MySQL dumps causing errors when I tried to import them into the staging database.

I had to run some SQL queries to find which tables and columns were wrong, and to set the correct charset and collation. This fixed the previous error and I could import the MySQL dump.

The reason I think this may be related is because when I looked up solutions for that issue, one of the solutions recommended disabling foreign keys for the table alter statements, and re-enabling them after:

SET FOREIGN_KEY_CHECKS=0;

-- Insert your other SQL Queries here...

SET FOREIGN_KEY_CHECKS=1;

In the next section, some of the errors outputted by the Drush Watchdog come from Drupal\Core\Database\IntegrityConstraintViolationException so I am wondering if my earlier fix may have instead broken something in the database.

The other major change since I last tried to create a menu item is that I updated Drupal 10.1.4 to 10.1.6.

Drush Watchdog Output

I found a few issues discussing this on the Drupal forum. Most of these are VERY old, around 7-10 year. The fixes were not recommended as per the comments, however this command I found on one of the issues provides a log of some of these error messages:

drush watchdog-show
 ------ -------------- ------------------- ---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  ID     Date           Type                Severity   Message                                                                                                                                                                                       
 ------ -------------- ------------------- ---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  1593   17/Nov 10:45   php                 Error      Drupal\Core\Entity\EntityStorageException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default value: INSERT INTO "menu_tree" ("id", "menu_name") VALUES (:db_insert_  
  1592   17/Nov 10:45   menu_link_content   Error      Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default value: INSERT INTO "menu_tree" ("id", "menu_name") VA  
  1591   17/Nov 10:41   php                 Error      Drupal\Core\Entity\EntityStorageException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default value: INSERT INTO "menu_tree" ("id", "menu_name") VALUES (:db_insert_  
  1590   17/Nov 10:41   menu_link_content   Error      Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default value: INSERT INTO "menu_tree" ("id", "menu_name") VA  
  1589   17/Nov 10:40   menu                Error      Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default value: INSERT INTO "menu_tree" ("id", "menu_name") VA  
  1588   17/Nov 10:40   views               Info       The view Statistics has been deleted.                                                                                                                                                         
  1587   16/Nov 16:53   php                 Error      Symfony\Component\HttpKernel\Exception\HttpException: The specified #ajax callback is empty or not callable. in Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse() (line 67 of /Users  
  1586   16/Nov 16:53   menu                Error      Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default value: INSERT INTO "menu_tree" ("id", "menu_name") VA  
  1585   16/Nov 16:40   menu                Error      Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default value: INSERT INTO "menu_tree" ("id", "menu_name") VA  
  1584   16/Nov 16:40   system              Info       charts_billboard module installed.                                                                                                                                                            
 ------ -------------- ------------------- ---------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Drush updb Output

I found another issue where numerous users had a similar issue and resolved it with drush updb. I ran this and got the same error output.

drush updb 
 [success] No pending updates.
 [error]  Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[HY000]: General error: 1364 Field 'parent' doesn't have a default value: INSERT INTO "menu_tree" ("id", "menu_name") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array
(
    [:db_insert_placeholder_0] => charts.settings
    [:db_insert_placeholder_1] => tools
)
 in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 43 of /Users/ciesinsg/Documents/Repositories/cab/web/core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php). 

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.