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], ) 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"] )