diff --git a/django/db/models/base.py b/django/db/models/base.py index 787dcd026e..13c15d555a 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -165,7 +165,7 @@ class Model(object): 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 diff --git a/tests/modeltests/custom_pk/models.py b/tests/modeltests/custom_pk/models.py index 6193852adf..f7b790ca21 100644 --- a/tests/modeltests/custom_pk/models.py +++ b/tests/modeltests/custom_pk/models.py @@ -8,7 +8,8 @@ this behavior by explicitly adding ``primary_key=True`` to a field. from django.db import models 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) last_name = models.CharField(maxlength=20) class Meta: