8

When trying to run my tests (python manage.py test) I am getting:

CommandError: Database test_db 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.py sqlflush'. That's the SQL this command wasn't able to run.
The full error: cannot truncate a table referenced in a foreign key constraint
DETAIL:  Table "install_location_2015_05_13" references "app".
HINT:  Truncate table "install_location_2015_05_13" at the same time, or use TRUNCATE ... CASCADE.

I am using partitions in our project which are generated on the fly via a python function (so I can run it periodically). I don't have any models for these partitions.

The partition maintenance function is invoked after syncdb triggers the post_syncdb signal (so it is executed when the test database is set up).

How can I make Django clear the additional tables (partitions)? or How can I tell Django to use CASCADE while running the tests?

1 Answer 1

0

Mainly problem occur where we change relation in M2M field. Old constraint remain and new constraint for new relation was created. Fixed in Django 1.8

3
  • 3
    I still experience that with Django==2.0.2 Feb 22, 2018 at 18:03
  • 4
    me too with Django==3.1.2
    – Tom
    Jan 27, 2021 at 23:21
  • the problem is still present on django==4.2.10
    – herickmota
    Feb 26 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.