After deleting an old Model in my Django micro-service, pytest fails to setup the test DB. The migrations fail to execute correctly. However, the migration generated after the model deletion works well on my staging DB. The problem is only impacting new DBs and in this case, the one created by pytest.
What I did to delete my model:
- Remove all use cases of my model
- Delete my model
- Makemigrations
- Migrate
The pytest DB-creation step is replaying the migrations history. It should:
- Create my model
- Define constraints
- Delete my model as I want to delete it
The error makes me think the creation of the model is deferred as Django see that it is deleted later, and so the model constraints seem to be executed before the creation of the model.
self = <django.db.backends.utils.CursorWrapper object at 0x114590198>
sql = 'ALTER TABLE "catalogue_productoffer_competitors" ADD CONSTRAINT "catalogue_productoff_competitor_id_99767623_fk_categorie" FOREIGN KEY ("competitor_id") REFERENCES "categories_competitor" ("id") DEFERRABLE INITIALLY DEFERRED'
django.db.utils.ProgrammingError: relation "categories_competitor" does not exist
Thanks for your help !