Running the test suite against Postgres freezes

I was following Unit tests part of “Contributing to Django” docs.

Running tests against SQLite with default settings worked fine.
However, when I tried to run the suite against Postgres, it froze repeatedly after running 5906 tests.
I did some digging:

  • some subsets of tests (eg ./ --settings=postgres_test_settings -v=2 generic_relations) work fine;

  • running ./ --settings=postgres_test_settings -v=2 auth_tests freezes, but produces an error on Ctrl+C:

django.db.utils.IntegrityError: insert or update on table "auth_permission" violates foreign key constraint "auth_permission_content_type_id_2f476e4b_fk_django_co"
DETAIL:  Key (content_type_id)=(16) is not present in table "django_content_type".
  • running ./ --settings=postgres_test_settings -v=2 auth_tests.test_migrations fails 1/10 tests with the same error as above;

  • running ./ --settings=postgres_test_settings -v=2 auth_tests.test_models freezes, but shows that 49/50 tests passed and shows no errors after Ctrl+C.

I googled an error message, Django ticket #10827 came up. I added INSTALLED_APPS to my Postgres settings, but that did not help.

Am I missing something in my Postgres settings? Maybe someone can give an example of working Postgres settings?

Any advice on how to debug this further, or should I open a ticket in Django Trac?

Django version:
(4, 1, 0, 'alpha', 0)
Postgres version:
PostgreSQL 12.9 (Ubuntu 12.9-2.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit


The django-docker-box project has postgres settings: django-docker-box/ at main · django/django-docker-box · GitHub

I note these use a Django user and database, rather than “postgres”, which might have some permissions issues. Try that?

Otherwise, yes you can open a ticket. A full stack trace would be useful rather than just the exceptino.

1 Like

Hi Adam,
Thanks for reply!

I noticed that django-docker-box settings had different DB names for ‘default’ and ‘other’ databases - once I changed that in my settings, tests worked.