diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php index 6673d1fbaede785a97ed189bfc49f8d0c40c3340..bea11d75d99f6477639d13528e54b92ad3ed4e96 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php @@ -489,6 +489,13 @@ public function dropField($table, $field) { $new_schema = $old_schema; unset($new_schema['fields'][$field]); + + // Handle possible primary key changes. + if (isset($new_schema['primary key']) && ($key = array_search($field, $new_schema['primary key'])) !== FALSE) { + unset($new_schema['primary key'][$key]); + } + + // Handle possible index changes. foreach ($new_schema['indexes'] as $index => $fields) { foreach ($fields as $key => $field_name) { if ($field_name == $field) { diff --git a/core/modules/system/src/Tests/Database/SchemaTest.php b/core/modules/system/src/Tests/Database/SchemaTest.php index a59b9d9a0ed9dc12a68ee0b3158d072c2e7fc57a..7811b505b2707742631b5cc427fc01cadbd5579b 100644 --- a/core/modules/system/src/Tests/Database/SchemaTest.php +++ b/core/modules/system/src/Tests/Database/SchemaTest.php @@ -444,6 +444,11 @@ protected function assertFieldAdditionRemoval($field_spec) { // Clean-up. db_drop_field($table_name, 'test_field'); + + // Add back the field and then try to delete a field which is also a primary + // key. + db_add_field($table_name, 'test_field', $field_spec); + db_drop_field($table_name, 'serial_column'); db_drop_table($table_name); }