Error with save or update

Created on 6 September 2024, 3 months ago
Updated 12 September 2024, 2 months ago

Problem/Motivation

Drupal\Core\Entity\EntityStorageException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'field_tpeck_txcat_ptpqv_sel_vms_value' at row 1: INSERT INTO "tip_eck_tax_cat__field_tpeck_txcat_ptpqv_sel_vms" ("entity_id", "revision_id", "bundle", "delta", "langcode", "field_tpeck_txcat_ptpqv_sel_vms_value") 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); Array ( [:db_insert_placeholder_0] => 3 [:db_insert_placeholder_1] => 3 [:db_insert_placeholder_2] => tip_eck_txcat_pack_tour_porqviaj [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => es [:db_insert_placeholder_5] => additional_special_touches_for_our_service_for_icons ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @Nelo_Drup
  • First commit to issue fork.
  • Assigned to hctom
  • Issue was unassigned.
  • Status changed to Needs review 3 months ago
  • 🇩🇪Germany hctom

    Good catch, thanks for the report. The field's value column length did not correspond to the actually allowed maxmimum length of view mode names. The issue fork provides a fix for that by increasing the column's length to 64 in the database.

    Please remember to run database updates before testing this patch, because the schema is updated for all existing view mode switch fields with the new length.

  • Assigned to SteffenR
  • 🇩🇪Germany SteffenR Germany

    I'll have a look on it and hope the error is fixed.

  • Issue was unassigned.
  • Status changed to Needs work 2 months ago
  • 🇩🇪Germany SteffenR Germany

    Unfortunately you hook_update_n is not working, if you have a database with existing content.

    ------------------ ----------- --------------- -------------------------------------------------------------------------------
      Module             Update ID   Type            Description
     ------------------ ----------- --------------- -------------------------------------------------------------------------------
      view_mode_switch   10201       hook_update_n   10201 - Increase max length of all view mode switch 'value' property columns.
     ------------------ ----------- --------------- -------------------------------------------------------------------------------
    
     // Do you wish to run the specified pending updates?: yes.
    
    >  [notice] Update started: view_mode_switch_update_10201
    >  [error]  The SQL storage cannot change the schema for an existing field (field_column_layout in paragraph entity) with data.
    >  [error]  Update failed: view_mode_switch_update_10201
    
  • Status changed to Needs review 2 months ago
  • 🇮🇳India Rohit Rana

    The issue you're facing is related to the hook_update_N() .it only changes the schema for future operations and does not automatically handle existing data that exceeds the new schema constraints.

    You can try the following steps: 
    1. Back up your data.

    2. Identify the fields that have data exceeding the length constraint and truncate those values so that they comply with the updated schema.

    3.Once the data is truncated, you can proceed with updating the schema using your hook_update_N() function. 

    4. Restore the data

  • Assigned to hctom
  • Status changed to Needs work 2 months ago
  • 🇩🇪Germany hctom

    @steffenr thanks for testing. I'll check later, why it is not working, because it worked on my side with data in a view mode switch field's table ;)

    @rohit rana: The length of the field is INCREASED in the schema... so you do not have to backup/truncate/restore anything. If so, the update hook would be quite useless ;)

    Back to needs work and assigning it to me.

  • 🇩🇪Germany hctom

    Unfortunately the column_changes_handled field storage setting (which is needed to alter a field's storage schema, if there is already field data available) is first introduced with Drupal 10.3 - see Provide a flag to allow updates to stored schema for fields Fixed

    I am currently looking for another way to do this for Drupal >= 10.2. If there is none, this issue will increase the required core version to 10.3.

  • Status changed to Needs review 2 months ago
  • 🇩🇪Germany hctom

    Finally got the update hook working forDrupal >= 10.2. Please review again - at best with Drupal 10.2.x, 10.3.x and 11.x sites that already contain data.

  • Great, that update will be integrated into the modules

  • Status changed to RTBC 2 months ago
  • 🇨🇷Costa Rica yuvania

    I tried it on drupal 10.3 and it worked fine for me

  • 🇩🇪Germany SteffenR Germany

    I just did a quick test run in Drupal 10.2 with existing values and the hook_update_n was working as expected. The length of the field is set to 64.

    Thanks @hctom

  • 🇩🇪Germany hctom

    I personally also did a basic check with Drupal 11.0.4 and everything worked fine - also with already available field data. So let's get this merged ;)

  • Pipeline finished with Skipped
    2 months ago
    #281064
    • hctom committed cc320910 on 2.x
      Issue #3472629 by hctom, nelo_drup, steffenr, yuvania: Error with save...
  • Status changed to Fixed 2 months ago
  • Status changed to Fixed 2 months ago
Production build 0.71.5 2024