While debugging a unit test in Django, I placed the following statement in my code
Student.objects.filter(id__in=[1,2]).delete()
...
import pdb; pdb.set_trace()
At the breakpoint, if I type Student.objects.count()
, I can see that it has reduced due to delete however if I open psql
(PostgreSQL command line) and check the test_database
, I can still see the rows (which have been deleted according to Django). Why do I see this inconsistency between Django ORM & the database. Does the ORM cache my queries? How can I make it commit to the database at the breakpoint?
Update:
Quick solution for debugging. Add the following lines at breakpoint to see the data in psql
. Thanks to @DanielRoseman for the tip.
from django.db import connection
connection.cursor().execute('commit;')