- Issue created by @Nelo_Drup
- First commit to issue fork.
- Merge request !39#3472629: Increase 'value' property column length to 64 → (Merged) created by hctom
- Assigned to hctom
- Issue was unassigned.
- Status changed to Needs review
3 months ago 10:05pm 6 September 2024 - 🇩🇪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 12:21pm 9 September 2024 - 🇩🇪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 1:19pm 9 September 2024 - 🇮🇳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 2:24pm 9 September 2024 - 🇩🇪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 FixedI 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 3:47pm 10 September 2024 - 🇩🇪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.
- Status changed to RTBC
2 months ago 8:08pm 11 September 2024 - 🇩🇪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 ;)
- Status changed to Fixed
2 months ago 11:14am 12 September 2024 - Status changed to Fixed
2 months ago 11:14am 12 September 2024