﻿id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 1394 primary_key with db_column set results in errors in admin mooquack@… nobody "Take the following model, for example: {{{ class A(meta.Model): pri_key = meta.AutoField('ID', db_column='id', primary_key=True) title = meta.CharField(maxlength=30) class META: admin = meta.Admin( fields = ( (None, {'fields': ('title',)}), ), list_display = ('title',), ) def __repr__(self): return self.title }}} If an object of this model is edited in the admin, clicking ""save"" will result in a ProgrammingError like the following: {{{ ProgrammingError at /admin/testapp/as/1/ ERROR: column ""pri_key"" does not exist UPDATE ""testapp_as"" SET ""title""='Blah blah blah' WHERE ""pri_key""='1' }}} In short, the admin is not listening to pri_key's db_column option. Searching through the code finds a few places where it was assumed the primary key's name and db column would never be different. Since I'm not sure how to create a diff (embarrased cough), here are the lines of code that need to be changed: {{{ In django/core/meta/__init__.py, line 1006: db.db.quote_name(opts.pk.attname)), Becomes: db.db.quote_name(opts.pk.column)), }}} {{{ In django/contrib/admin/views/main.py, line 453: pk_value = getattr(new_object, opts.pk.column) Becomes: pk_value = getattr(new_object, opts.pk.attname) }}} It works flawlessly after making these changes." defect closed contrib.admin master normal fixed primary key admin onetoonefield db_column Accepted 0 0 0 0