﻿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
3077	[patch] multi-degree ForeignKey/OneToOne relationships with non-integer primary key	Nikolaus Schlemm <nikl@…>	Andy Durdin	"this is closely related to [#343 ForeignOne-to-one relations - different primary_key] and [#2783 Small patch to make One to One fields work with any data type]:

imagine a setup like this:
{{{
class A(models.Model):
    key = models.CharField(maxlength=10, primary_key=True)

class B(models.Model):
    a = models.OneToOneField(A)

class C(models.Model):
    a = models.ForeignKey(A)
    b = models.OneToOneField(B)

class D(models.Model):
    a = models.ForeignKey(A)
    b = models.ForeignKey(B)
    c = models.OneToOneField(C)
}}}

while django correctly constructs
{{{
CREATE TABLE ""testapp_a"" (
    ""key"" varchar(10) NOT NULL PRIMARY KEY
);
CREATE TABLE ""testapp_b"" (
    ""a_id"" varchar(10) NOT NULL PRIMARY KEY REFERENCES ""testapp_a"" (""key"")
);
}}}

but it erronously constructs the fields farther away with integer fields:
{{{
CREATE TABLE ""testapp_c"" (
    ""a_id"" varchar(10) NOT NULL REFERENCES ""testapp_a"" (""key"")
    ""b_id"" integer NOT NULL PRIMARY KEY,
);
CREATE TABLE ""testapp_d"" (
    ""a_id"" varchar(10) NOT NULL REFERENCES ""testapp_a"" (""key"")
    ""b_id"" integer NOT NULL REFERENCES ""testapp_b"" (""a_id""),
    ""c_id"" integer NOT NULL PRIMARY KEY REFERENCES ""testapp_c"" (""b_id""),
);
}}}

I'll try to come up with a patch asap"	defect	closed	Database layer (models, ORM)	dev	major	fixed	qsrf		Accepted	0	0	0	0	0	0
