Fatal error when title field is empty(Integrity constraint violation)

Created on 13 March 2020, almost 5 years ago
Updated 12 March 2024, 9 months ago

What are the steps required to reproduce the bug? :
Create a content type without a mandatory title and leave the title field empty during submit

What behavior were you expecting?

I did not do this on purpose, it looks like the title field is not mandatory on my install and thus users can leave it empty. This results in an fatal error. I expected a cleaner error message.

What happened instead?
Install gave the error 'oops, something whent wrong. please contact you sysadmin'

Dblog shows the following error occured:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null: INSERT INTO {node_field_data} (nid, vid, type, langcode, status, uid, title, created, changed, promote, sticky, default_langcode, revision_translation_affected, page_views) 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); Array ( [:db_insert_placeholder_0] => 8685 [:db_insert_placeholder_1] => 14463 [:db_insert_placeholder_2] => nieuws [:db_insert_placeholder_3] => nl [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => 1584096479 [:db_insert_placeholder_8] => 1584096859 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => 1 [:db_insert_placeholder_13] => ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (regel 846 van /var/www/.../core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

I only noticed that the title is not mandatory after i saved a node and forgot to set a title. Its a install that is migrated from drupal 7 after 8.8.0 had been released.

πŸ› Bug report
Status

Closed: duplicate

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated 1 day ago

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia collab

    I encountered this same problem after a 7->10 migration where title fields on some content types had lost their "required" property. I backed up the database in PHPadmin, searched the "config" table for "node.type.", found entries that were overriding titles of the affected content types and deleted them. After clearing the caches, the "required" property was back in place. Thankfully, nothing else appears to have been significantly affected by this action!

  • πŸ‡¨πŸ‡¦Canada leducdubleuet Chicoutimi QC

    In a project, the title field was required in Drupal 7 for my content types. Once migrated to Drupal 9 and now 10, the title field is not required anymore causing the same integrity constraint violation stated here.

    I looked in the config table and there is no entry overriding titles so I am left with content types without required titles causing the error when saving with an empty title.

    How can I have the titles back as required like it was in D7?

  • This is a duplicate of the referenced issues.

  • πŸ‡¨πŸ‡¦Canada leducdubleuet Chicoutimi QC

    OK, I found a way to put back my titles as required quite easily.

    I exported my configurations using "drush config:export" and then I edited the corresponding title yml files to put them back as required.

    For example, for the page content type, we edit the file "core.base_field_override.node.page.title.yml" and modify the line "required: false" to "required: true".

    And then I imported back my configurations using "drush config:import --partial --diff".

    TaDa! The titles are now required as needed!

  • Status changed to Closed: duplicate 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States papagrande US West Coast

    The tip in #15 is helpful (as is https://www.drupal.org/project/drupal/issues/2358537#comment-12648753 ✨ Do not require a 'title' field Needs work ), but this issue does duplicate several other currently open issues.

Production build 0.71.5 2024