#QuerySet.update() returning SQL errors.
11 messages · Page 1 of 1 (latest)
Can you show the update you're doing with the raw sql versus the update you're doing with the queryset please?
@last raptor here it is:
UPDATE function_success_tracker SET queue = 1 WHERE pyfunction = “some_value”
functions_to_run = selected_rows.values("pyfunction").distinct()
query_set = FunctionSuccessTracker.objects.filter(pyfunction__in=functions_to_run)
query_set.update(queue="1")
But this will run on all rows?
Unless pyfunction can be NULL, possibly?
Or no. Because you start with a (i assume) sunset. But it will potentially run on more rows than selected rows 🤔
Do you mind running the following in the python shell?
>>> from django.db import connection
>>> connection.queries_log.clear()
>>> # Run your code until and including update
...
>>> print(connection.queries)
The purpose of running this, is to see what django is running versus what you're manually running. You should be able to spot the issue.
It is fine if it updates multiple rows, it is intended to.
A better version of the SQL would be UPDATE function_success_tracker SET queue = 1 WHERE pyfunction IN (some, list)
I will run this when I am back at my computer 😊 I presume I should be looking to see if the printed SQL query is similar to the one I think it should be doing?
Precisely, you could also copy that and run it to test.