#28368: Model Inheritance Primary Key Issue
--------------------------------------------+------------------------
Reporter: Lawrence Elitzer | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
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?
--
Ticket URL: <https://code.djangoproject.com/ticket/28368>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.12887785335d6cfde89dbacbcd4b893e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.