Opened 10 years ago

Closed 10 years ago

#21761 closed Uncategorized (invalid)

Confused about "Forced update did not affect any rows."

Reported by: jeroen.pulles@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a DatabaseError("Forced update did not affect any rows.") (from model.save_base).

I cannot reproduce the error; Manually running save(force_update) on not-really-changed objects of the same type in a Django shell doesn't raise this exception.

What does this exception apply to?

I am under the impression that the model.save() force_insert/force_update arguments are there to get control over database operations. And as such I was expecting that force_update would work like a SQL UPDATE: Trying to overwrite a field with the same value is just fine.

I'm submitting this as a ticket as I don't understand why it would be bad that an update didn't affect any rows. I don't care if there is any difference between the stored data and the model when I call .save() on a model. That would be application logic, I think.

And as an aside: The MySQL database I'm using reports a "0 rows affected" on a SQL UPDATE statement with identical values. It doesn't return a warning or anything.

Change History (1)

comment:1 by Shai Berger, 10 years ago

Resolution: invalid
Status: newclosed

I'd expect this to happen when the object you are trying to update is not found in the database; the most likely scenario is calling save(force_update=True) with an object you've just created in memory, and have never saved; other scenarios are possible. When this is the case, not affecting any rows is indeed a bug in your code.

In the future, please ask such questions on the django-users list; you would have probably gotten an answer much faster there.


Note: See TracTickets for help on using tickets.
Back to Top