From 6cd48a6d5d2295729a1f237bf297e0bb83926771 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sun, 19 Apr 2015 14:27:23 +0200
Subject: [PATCH] Issue #2463263 by amateescu: SQLite: Fix
 system\Tests\Entity\EntityDefinitionUpdateTest

---
 core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php | 7 +++++++
 core/modules/system/src/Tests/Database/SchemaTest.php  | 5 +++++
 2 files changed, 12 insertions(+)

diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php
index 6673d1fbaede..bea11d75d99f 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 a59b9d9a0ed9..7811b505b270 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);
   }
 
-- 
GitLab