diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php index ce14ffea089..1aec2d779bc 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -249,7 +249,7 @@ EOD; } $sql_keys = []; - if (isset($table['primary key']) && is_array($table['primary key'])) { + if (!empty($table['primary key']) && is_array($table['primary key'])) { $sql_keys[] = 'CONSTRAINT ' . $this->ensureIdentifiersLength($name, '', 'pkey') . ' PRIMARY KEY (' . $this->createPrimaryKeySql($table['primary key']) . ')'; } if (isset($table['unique keys']) && is_array($table['unique keys'])) { diff --git a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php index d638996cc8f..75e4963104c 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php @@ -1009,7 +1009,7 @@ class SchemaTest extends KernelTestBase { $this->assertSame(['id3', 'test_field_2', 'id4'], $method->invoke($schema, 'table_with_pk_3')); // Test with table without a primary key. - $schema->createTable('table_without_pk', [ + $schema->createTable('table_without_pk_1', [ 'description' => 'Table without primary key.', 'fields' => [ 'id' => [ @@ -1022,7 +1022,24 @@ class SchemaTest extends KernelTestBase { ], ], ]); - $this->assertSame([], $method->invoke($schema, 'table_without_pk')); + $this->assertSame([], $method->invoke($schema, 'table_without_pk_1')); + + // Test with table with an empty primary key. + $schema->createTable('table_without_pk_2', [ + 'description' => 'Table without primary key.', + 'fields' => [ + 'id' => [ + 'type' => 'int', + 'not null' => TRUE, + ], + 'test_field' => [ + 'type' => 'int', + 'not null' => TRUE, + ], + ], + 'primary key' => [], + ]); + $this->assertSame([], $method->invoke($schema, 'table_without_pk_2')); // Test with non existing table. $this->assertFalse($method->invoke($schema, 'non_existing_table'));