Change record status: 
Project: 
Introduced in branch: 
11.5.x
Introduced in version: 
11.5.0
Description: 

Specifying limited length for primary and unique keys is now forbidden. In any case, most DBs do not allow that anyway, so now Drupal just standardize on that. Only indexes allow that.

The Database Schema Definition API introduced in #3411490: Replace array-based DB Schema API with a value object structure prevents that on the specification level, but Schema methods still allow that, and that is now deprecated.

In Drupal 11.5 this is deprecated:

    $this->connection->schema()->createTable('mytable', [
      'fields' => [
        'id' => [
          'type' => 'varchar',
          'length' => 50,
        ],
        'field' => [
          'type' => 'varchar',
          'length' => 50,
        ],
      ],
      'primary key' => [['id', 10]],
      'unique keys' => [
        'field' => [['field', 10]],
      ],
    ]);

and as of Drupal 13 will throw a SchemaException. Instead, if using direct Schema method calls and not the Database Schema Definition API, define only full columns in primary and unique keys:

    $this->connection->schema()->createTable('mytable', [
      'fields' => [
        'id' => [
          'type' => 'varchar',
          'length' => 50,
        ],
        'field' => [
          'type' => 'varchar',
          'length' => 50,
        ],
      ],
      'primary key' => ['id'],
      'unique keys' => [
        'field' => ['field'],
      ],
    ]);

This is allowed, for indexes:

    $this->connection->schema()->createTable('mytable', [
      'fields' => [
        'field' => [
          'type' => 'varchar',
          'length' => 50,
        ],
      ],
      'indexes' => [
        'field' => [['field', 10]],
      ],
    ]);
Impacts: 
Module developers