summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFiza Ashraf <68822806+fizaashraf37@users.noreply.github.com>2022-08-06 13:51:43 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-08-08 06:28:53 +0200
commitc0beff21239e70cbdcc9597e5be09e505bb8f76c (patch)
treef0d70c820f25a0f48472d4b27b6196a7fbf9e381
parentfd93db97c7228b16a4f92f97ef05b0d72418d952 (diff)
Fixed #33899 -- Fixed migration crash when removing indexed field on SQLite 3.35.5+.
Regression in 702819227fd0cdd9b581cd99e11d1561d51cbeb. Thanks cessor for the report.
-rw-r--r--AUTHORS1
-rw-r--r--django/db/backends/sqlite3/schema.py5
-rw-r--r--docs/releases/4.1.1.txt3
-rw-r--r--tests/schema/tests.py11
4 files changed, 18 insertions, 2 deletions
diff --git a/AUTHORS b/AUTHORS
index 356680682a..48359498f6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -322,6 +322,7 @@ answer newbie questions, and generally made Django that much better:
Filip Noetzel <http://filip.noetzel.co.uk/>
Filip Wasilewski <filip.wasilewski@gmail.com>
Finn Gruwier Larsen <finn@gruwier.dk>
+ Fiza Ashraf <fizaashraf37@gmail.com>
Flávio Juvenal da Silva Junior <flavio@vinta.com.br>
flavio.curella@gmail.com
Florian Apolloner <florian@apolloner.eu>
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py
index 55fdf5fbfe..6c106ae868 100644
--- a/django/db/backends/sqlite3/schema.py
+++ b/django/db/backends/sqlite3/schema.py
@@ -408,10 +408,11 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
# For explicit "through" M2M fields, do nothing
elif (
self.connection.features.can_alter_table_drop_column
- # Primary keys, unique fields, and foreign keys are not
- # supported in ALTER TABLE DROP COLUMN.
+ # Primary keys, unique fields, indexed fields, and foreign keys are
+ # not supported in ALTER TABLE DROP COLUMN.
and not field.primary_key
and not field.unique
+ and not field.db_index
and not (field.remote_field and field.db_constraint)
):
super().remove_field(model, field)
diff --git a/docs/releases/4.1.1.txt b/docs/releases/4.1.1.txt
index 7339390ffa..2e61e3877d 100644
--- a/docs/releases/4.1.1.txt
+++ b/docs/releases/4.1.1.txt
@@ -26,3 +26,6 @@ Bugfixes
* Fixed a regression in Django 4.1 that caused a crash of
:class:`~django.db.models.expressions.Window` expressions with
:class:`~django.contrib.postgres.aggregates.ArrayAgg` (:ticket:`33898`).
+
+* Fixed a regression in Django 4.1 that caused a migration crash on SQLite
+ 3.35.5+ when removing an indexed field (:ticket:`33899`).
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 0702b54135..a72e6906bb 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -813,6 +813,17 @@ class SchemaTests(TransactionTestCase):
False,
)
+ def test_remove_indexed_field(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(AuthorCharFieldWithIndex)
+ with connection.schema_editor() as editor:
+ editor.remove_field(
+ AuthorCharFieldWithIndex,
+ AuthorCharFieldWithIndex._meta.get_field("char_field"),
+ )
+ columns = self.column_classes(AuthorCharFieldWithIndex)
+ self.assertNotIn("char_field", columns)
+
def test_alter(self):
"""
Tests simple altering of fields