TransactionTestCase.available_apps, allow_cascade=True - db cannot be flushed

My code:

  • I am using multiple postgresql schemas for my models, postgresql12 with out-of-box ubuntu 20.04 setup.
  • I am performing unit tests of some code which uses transactions.
  • When running other non-transaction tests with django TestCase, everything works normal.
  • When running transaction tests with TransactionTestCase, this happens:
django.db.utils.NotSupportedError: cannot truncate a table referenced in a foreign key constraint
DETAIL:  Table "users_user_permissions" references "auth_permission".
HINT:  Truncate table "users_user_permissions" at the same time, or use TRUNCATE ... CASCADE.
...
django.core.management.base.CommandError: Database test_mike3 couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin sqlflush'. That's the SQL this command wasn't able to run.

django-admin sqlflush:

BEGIN;
TRUNCATE "django_content_type", "auth_group_permissions", "django_session", "auth_group", "auth_permission", "django_admin_log" RESTART IDENTITY;                                                                                                                           
COMMIT;

I have gone into code and added _fixture_teardown(self) override to my ExampleTestCase(TransactionTestCase): basically changed allow_cascade=True in flush command.

Since by this documentation: Advanced testing topics | Django documentation | Django not setting available_apps might cause memory leaks, I will probably set all my apps to it so allow_cascade is set to True automatically.

Any idea why is it unable to flush db with TransactionTestCase? Thanks.

I have the same problem. Did you reach any conclusion?