﻿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
10406	Primary keys with model inheritance problems.	Ramiro Morales	Malcolm Tredinnick	"With this model setup:

{{{
#!python
from django.db import models

class Persona(models.Model):
    nombre = models.CharField(max_length=60)

class Cliente(Persona):
    cli_id = models.AutoField(primary_key=True)
    persona = models.OneToOneField(Persona, parent_link=True)
}}}

`sqlall` output (with SQLite, MySQL shows the same) shows that the two Client fields are declared `PRIMARY KEY`:

{{{
#!sql
CREATE TABLE ""thread1_persona"" (
    ""id"" integer NOT NULL PRIMARY KEY,
    ""nombre"" varchar(60) NOT NULL
)
;
CREATE TABLE ""thread1_cliente"" (
    ""cli_id"" integer NOT NULL PRIMARY KEY,
    ""persona_id"" integer NOT NULL PRIMARY KEY REFERENCES ""thread1_persona"" (""id"")
)
;
COMMIT;
}}}

Problem also show if the explicit Cliente PK is changed from AutoField to another field type.

Commenting out http://code.djangoproject.com/browser/django/trunk/django/db/models/base.py#L101
solves the problem (and Django test suite still passes):

{{{
#!sql
BEGIN;
CREATE TABLE ""thread1_persona"" (
    ""id"" integer NOT NULL PRIMARY KEY,
    ""nombre"" varchar(60) NOT NULL
)
;
CREATE TABLE ""thread1_cliente"" (
    ""cli_id"" integer NOT NULL PRIMARY KEY,
    ""persona_id"" integer NOT NULL UNIQUE REFERENCES ""thread1_persona"" (""id"")
)
;
COMMIT;
}}}

If Cliente is changed to inherit from models.Model, problem also goes away.

This issue could be related to #10251, but the example posted there doesn't show this double PK problem because it isn't using an explicit OneToOneField with parent_link for the inheritance."		closed	Database layer (models, ORM)	dev		fixed	parent_link primary_key onetoonefield		Accepted	0	0	0	0	0	0
