﻿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
10251	Problem with inheritance plus explicit primary_key in child model	Karen Tracey	Malcolm Tredinnick	"Given these models:

{{{
#!python
class BaseM(models.Model):
  base_name = models.CharField(max_length=100)
  def __unicode__(self):
    return self.base_name

class DerivedM(BaseM):
  customPK = models.IntegerField(primary_key=True)
  derived_name = models.CharField(max_length=100)
  def __unicode__(self):
    return ""PK = %d, base_name = %s, derived_name = %s"" % \
        (self.customPK, self.base_name, self.derived_name) 
}}}

The ORM can't seem to properly link parent with child models (reformatted for readability):

{{{
Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type ""help"", ""copyright"", ""credits"" or ""license"" for more information.
(InteractiveConsole)
>>> from ttt.models import DerivedM
>>> from django.db import connection
>>> DerivedM.objects.create(customPK=44, base_name=""b1"", derived_name=""d1"")

<DerivedM: PK = 44, base_name = b1, derived_name = d1>
>>> DerivedM.objects.all()
[]
>>> connection.queries[-1]

{'time': '0.006',
'sql': u'SELECT
          `ttt_basem`.`id`,
          `ttt_basem`.`base_name`,
          `ttt_derivedm`.`basem_ptr_id`,
          `ttt_derivedm`.`customPK`,
          `ttt_derivedm`.`derived_name`
       FROM `ttt_derivedm` INNER JOIN `ttt_basem`
       ON (`ttt_derivedm`.`customPK` = `ttt_basem`.`id`) LIMIT 21'}

}}}

This was originally tracked down in this thread but the OP doesn't seem interested in pursuing:

http://groups.google.com/group/django-users/browse_thread/thread/5ee5d5dacb16b90/b133b55a9a92520d

Seems to me either an error should be reported on trying to override primary_key in the child model, or the parent-child link should work."		closed	Database layer (models, ORM)	1.0		fixed			Accepted	0	0	0	0	0	0
