0

ubuntu 22.04, mysql 8.0.35, postgresql 16.1, python 3.8.18, django 4.2

django default db = "mydb"

We have a large data set saved in "mydb", generating that takes a long time.

While using mysql db, I was able to fetch items from "mydb" like <ModelName>.objects.filter() in my test cases. I'm unsure if records are copied into "test_" db from "mybd" by django.

Then I switched to postgres, recreated the data. When I fetch the data in APiView, it's working fine. But in testcases all model queries return blank queryset.

Is there a workaround for testcases while using postgres so I would not have to recreate the data every time I run the tests ? Thanks.

3
  • They are not copied no, you should use a fixture, or create these in the test. Commented Dec 13, 2023 at 15:11
  • @willeM_VanOnsem using fixtures or creating data in the test will take ~20 minutes every time I run tests. Which is why I'm looking for a way to get it working as it was while using mysql. While I was using mysql, testcases were able to fetch the data from the main db, event when a test_ db was created & used by the testcase. Commented Dec 13, 2023 at 15:21
  • 2
    you can disable recreating the database each time: docs.djangoproject.com/en/5.0/ref/django-admin/… Commented Dec 13, 2023 at 15:29

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.