diff -u b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php --- b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -9,7 +9,6 @@ use Drupal\Core\Database\Database; use Drupal\Core\Database\Query\Condition; -use Drupal\Core\Database\SchemaException; use Drupal\Core\Database\SchemaObjectExistsException; use Drupal\Core\Database\SchemaObjectDoesNotExistException; use Drupal\Core\Database\Schema as DatabaseSchema; @@ -305,9 +304,6 @@ * * @return array * List of shortened indexes. - * - * @throws \Drupal\Core\Database\SchemaException - * Thrown if field specification is missing. */ protected function getNormalizedIndexes(array $spec) { $indexes = isset($spec['indexes']) ? $spec['indexes'] : []; @@ -315,17 +311,15 @@ foreach ($index_fields as $index_key => $index_field) { // Get the name of the field from the index specification. $field_name = is_array($index_field) ? $index_field[0] : $index_field; - // Check whether the field is defined in the table specification. + // Assert that the field is defined in the table specification. assert('isset($spec[\'fields\'][$field_name])', "MySQL needs the '$field_name' field specification in order to normalize the '$index_name' index"); - if (isset($spec['fields'][$field_name])) { - // Get the MySQL type from the processed field. - $mysql_field = $this->processField($spec['fields'][$field_name]); - if (in_array($mysql_field['mysql_type'], $this->mysqlStringTypes)) { - // Check whether we need to shorten the index. - if ((!isset($mysql_field['type']) || $mysql_field['type'] != 'varchar_ascii') && (!isset($mysql_field['length']) || $mysql_field['length'] > 191)) { - // Limit the index length to 191 characters. - $this->shortenIndex($indexes[$index_name][$index_key]); - } + // Get the MySQL type from the processed field. + $mysql_field = $this->processField($spec['fields'][$field_name]); + if (in_array($mysql_field['mysql_type'], $this->mysqlStringTypes)) { + // Check whether we need to shorten the index. + if ((!isset($mysql_field['type']) || $mysql_field['type'] != 'varchar_ascii') && (!isset($mysql_field['length']) || $mysql_field['length'] > 191)) { + // Limit the index length to 191 characters. + $this->shortenIndex($indexes[$index_name][$index_key]); } } } only in patch2: unchanged: --- a/core/modules/system/src/Tests/Database/SchemaTest.php +++ b/core/modules/system/src/Tests/Database/SchemaTest.php @@ -298,18 +298,6 @@ function testIndexLength() { $schema_object = Database::getConnection()->schema(); - // Ensure expected exception thrown when adding index with missing info. - $expected_exception_message = "MySQL needs the 'test_field_text' field specification in order to normalize the 'test_regular' index"; - $missing_field_spec = $table_specification; - unset($missing_field_spec['fields']['test_field_text']); - try { - $schema_object->addIndex('test_table_index_length', 'test_separate', [['test_field_text', 200]], $missing_field_spec); - $this->fail('SchemaException not thrown when adding index with missing information.'); - } - catch (SchemaException $e) { - $this->assertEqual($expected_exception_message, $e->getMessage()); - } - // Add a separate index. $schema_object->addIndex('test_table_index_length', 'test_separate', [['test_field_text', 200]], $table_specification); $table_specification_with_new_index = $table_specification;