Does anyone know the actual query generated by django when you use F expression?
What will the generated query be for the example mentioned in the doc: https://docs.djangoproject.com/en/2.1/ref/models/expressions/#f-expressions
from django.db.models import F
reporter = Reporters.objects.get(name='Tintin')
reporter.stories_filed = F('stories_filed') + 1
reporter.save()
I tried viewing the query generated using:
from django.db import connection
logging.info('[----- DEBUG -----] Query -1: %s', connection.queries[-1])
logging.info('[----- DEBUG -----] Query -2: %s', connection.queries[-2])
logging.info('[----- DEBUG -----] Query -3: %s', connection.queries[-3])
but I don't see any query on the my model/table.
Anyone know how to figure this out?
The query should be there in connection.queries
- I just tested found it in there. The query sent to the database looks something like this for MySQL and Postgresql:
UPDATE "myapp_reporters"
SET "stories_filed" = ("myapp_reporters"."stories_filed" + 1)
WHERE "myapp_reporters"."id" = 123
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.