Closed
Description
What happened?
Description
When Craft applies new project config, if the definition of a column has changed in any way, Craft backs up the old column values before migrating. This is done in the Fields service.
However, the Fields service does not have a check on the length of that backup table name, and if it exceeds 64 characters, MySQL does not like that.
Steps to reproduce
- Create a new Matrix field with a long name: something like
learnMoreItems
worked for us! - Add a text field, call it
text
- Apply config changes
- Change the text field definition to trigger a backup on next project-config/apply (it's very likely that the error happens here but I haven't seen that)
- Run ./craft project-config/apply in a different environment
Expected behavior
The config applies with no error
Actual behavior
1059 Identifier name 'matrixcontent_learnmoreitems_field_block_text_zvjsmcfv_bak_1694160026' is too long
I have monkeypatched our instance with the following changes to the Fields service, but it's unlikely to be production-ready (it's fine for us for now though!):
do {
$suffix = $n === 1 ? '' : "_$n";
$bakTable = "{{%{$shortTableName}_{$column}_bak_$timestamp$suffix}}";
if (strlen($bakTable) > 64) {
$bakTableDiff = strlen($bakTable) - 64;
$shortColumn = substr($column, $bakTableDiff);
$bakTable = "{{%{$shortTableName}_{$shortColumn}_bak_$timestamp$suffix}}";
}
$n++;
} while ($db->tableExists($bakTable));
Craft CMS version
4.5.3
PHP version
8.2.10
Operating system and version
Docker php:8-fpm image
Database type and version
MySQL 5.7
Image driver and version
No response
Installed plugins and versions
No response