Fixed #2164 -- Create correct SQL when pk column name is not the same as the
attribute name. Thanks, Russell Cloran. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3130 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8938d5eeb3
commit
28e643743f
|
@ -165,7 +165,7 @@ class Model(object):
|
||||||
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
|
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
|
||||||
(backend.quote_name(self._meta.db_table),
|
(backend.quote_name(self._meta.db_table),
|
||||||
','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
|
','.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])
|
db_values + [pk_val])
|
||||||
else:
|
else:
|
||||||
record_exists = False
|
record_exists = False
|
||||||
|
|
|
@ -8,7 +8,8 @@ this behavior by explicitly adding ``primary_key=True`` to a field.
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
class Employee(models.Model):
|
class Employee(models.Model):
|
||||||
employee_code = models.CharField(maxlength=10, primary_key=True)
|
employee_code = models.CharField(maxlength=10, primary_key=True,
|
||||||
|
db_column = 'code')
|
||||||
first_name = models.CharField(maxlength=20)
|
first_name = models.CharField(maxlength=20)
|
||||||
last_name = models.CharField(maxlength=20)
|
last_name = models.CharField(maxlength=20)
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Reference in New Issue