Opened 19 years ago
Closed 19 years ago
#2164 closed defect (fixed)
[patch] Update SQL incorrect when db_column different to field name
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Hi,
When database column name is different to the field's name (attname), the update SQL is generated incorrectly. The following trivial patch fixes that:
--- django/db/models/base.py (revision 3129)
+++ django/db/models/base.py (working copy)
@@ -165,7 +165,7 @@
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
(backend.quote_name(self._meta.db_table),
','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
- backend.quote_name(self._meta.pk.attname)),
+ backend.quote_name(self._meta.pk.column)),
db_values + [pk_val])
else:
record_exists = False
Russell
Note:
See TracTickets
for help on using tickets.
(In [3130]) Fixed #2164 -- Create correct SQL when pk column name is not the same as the
attribute name. Thanks, Russell Cloran.