Problem/Motivation
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'entity_test_base_field_display_field__test_display_configurable__format' is too long: CREATE TABLE {entity_test} ( `id` INT unsigned NOT NULL auto_increment COMMENT 'The ID of the test entity.', `type` VARCHAR(255) NOT NULL COMMENT 'The bundle of the test entity.', `uuid` VARCHAR(128) NOT NULL COMMENT 'The UUID of the test entity.', `langcode` VARCHAR(12) NOT NULL COMMENT 'The language code of the test entity.', `name` VARCHAR(32) NULL DEFAULT NULL COMMENT 'The name of the test entity.', `user_id` INT unsigned NOT NULL COMMENT 'The ID of the associated user.', `test_no_display__value` VARCHAR(255) NULL DEFAULT NULL, `test_no_display__format` VARCHAR(255) NULL DEFAULT NULL, `test_display_configurable__value` VARCHAR(255) NULL DEFAULT NULL, `test_display_configurable__format` VARCHAR(255) NULL DEFAULT NULL, `test_display_non_configurable__value` VARCHAR(255) NULL DEFAULT NULL, `test_display_non_configurable__format` VARCHAR(255) NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `entity_test_base_field_display_field__uuid__value` (`uuid`), INDEX `entity_test_base_field_display_field__user_id__target_id` (`user_id`), INDEX `entity_test_base_field_display_field__test_no_display__format` (`test_no_display__format`), INDEX `entity_test_base_field_display_field__test_display_configurable__format` (`test_display_configurable__format`), INDEX `entity_test_base_field_display_field__test_display_non_configurable__format` (`test_display_non_configurable__format`) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'The base table for entity_test_base_field_display entities.'; Array ( ) in Drupal\Core\Database\Connection->query() (line 569 of /var/www/d8/core/lib/Drupal/Core/Database/Connection.php).
Proposed resolution
Truncate the maximum length and append some hash of the index name.
Remaining tasks
User interface changes
API changes
Comments
Comment #1
dawehnerMaybe something along like
Comment #2
berdirWe found the problem, EntityTestBaseFieldDisplay has the same base table as EntityTest, so it doesn't install itself a table, somehow, the order of entities has to be different for you, so it this one is checked first.
Comment #3
dawehnerIndeed a krsort() as well as a ksort() for the entity definitions in the module handler works fine.
I wonder whether we should also rename the table for that test entity?
Here is a patch which ensures that the index has the right name. This allows me to run these tests again.
Comment #4
dawehnerHere is a unit test.
Comment #5
plachYep, I think so: different entity types are not supposed to share tables.
I think the limit can be 36.
Also what about factoring out this logic in a Component static method so we can re-use it both here and when generating the field table name?
Comment #6
berdirYeah, we should absolutely update the table and also check if there are more of those. That module has lots of copy & pasted entity types.
Comment #7
plachFixed missing blank line :)
Comment #8
dawehnerThere we go.
Comment #9
dawehnerRelated issue
#2302057: Provide a component to truncate sql strings to a certain level
Comment #10
dawehnerComment #11
plachAwesome, thanks!
Please add Berdir in the commit message, he found out what was going on...
(genius at work :)
Comment #12
plachcrosspost...
Comment #13
plach@dawehner:
We should open also a follow-up to rename tables...
Comment #14
alexpottCommitted 5135cbb and pushed to 8.x. Thanks!