From 8b84364d469e394d9f04b4f96a7da1fc16d93fce Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 29 Sep 2025 23:01:12 +0200 Subject: [PATCH 1/2] Fixed assertIndexExists() crash when non-index constraint exists on the same columns. --- tests/migrations/test_base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/migrations/test_base.py b/tests/migrations/test_base.py index b636d18ec414..24ae59ca1b9a 100644 --- a/tests/migrations/test_base.py +++ b/tests/migrations/test_base.py @@ -108,6 +108,7 @@ def assertIndexExists( .values() if ( c["columns"] == list(columns) + and c["index"] is True and (index_type is None or c["type"] == index_type) and not c["unique"] ) From 906a51e125c3007f86d42b81072a1dad7149af05 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 29 Sep 2025 23:09:53 +0200 Subject: [PATCH 2/2] Skipped NOT NULL constraints on PostgreSQL 18+. Thanks Simon Charette for the implementation idea. --- django/db/backends/postgresql/introspection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py index 82013eb19113..fc69e0a381e1 100644 --- a/django/db/backends/postgresql/introspection.py +++ b/django/db/backends/postgresql/introspection.py @@ -206,7 +206,9 @@ def get_constraints(self, cursor, table_name): cl.reloptions FROM pg_constraint AS c JOIN pg_class AS cl ON c.conrelid = cl.oid - WHERE cl.relname = %s AND pg_catalog.pg_table_is_visible(cl.oid) + WHERE cl.relname = %s + AND pg_catalog.pg_table_is_visible(cl.oid) + AND c.contype != 'n' """, [table_name], )