﻿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
28368	Model Inheritance Primary Key Issue	Lawrence Elitzer	nobody	"I am using model inheritance and when I set my own primary_key in the parent class as one of the fields I define, when I try to create child objects with the same primary key I am NOT getting a duplicate error. Instead, it is overwriting the parent class fields. In the two child tables in the example code below, both parent pointers in the two child object tables point to the same parent record. 

{{{
# models.py
from django.db import models

class CommonImportedFile(models.Model):
    sha  = models.CharField(max_length=40, primary_key=True)
    name = models.CharField(max_length=200)

class FT1(CommonImportedFile):
    pass

class FT4(CommonImportedFile):
    pass
}}}

And here are the commands I am using:

{{{
from myapp.models import *
FT1.objects.create(name='ft1', sha='1234')
FT4.objects.create(name='ft4', sha='1234')
cf = CommonImportedFile.objects.get(sha='1234')
cf.name
}}}

cf.name is 'ft4' here indicating to me that the second object creation is overwriting the parent record entry since the primary_key 'sha' field is the same for both object creations. If you get rid of the primary_key attribute in the 'sha' field and instead put 'unique=True' then this works as I think it should. Seems like a bug to me, or am I using inheritance incorrectly here?"	Bug	new	Uncategorized	1.11	Normal				Unreviewed	0	0	0	0	0	0
