Opened 18 years ago
Closed 16 years ago
#3077 closed defect (fixed)
[patch] multi-degree ForeignKey/OneToOne relationships with non-integer primary key
Reported by: | Owned by: | Andy Durdin | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | major | Keywords: | qsrf |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
this is closely related to ForeignOne-to-one relations - different primary_key and 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
Attachments (2)
Change History (8)
by , 18 years ago
comment:1 by , 18 years ago
Summary: | multi-degree ForeignKey/OneToOne relationships with non-integer primary key → [patch] multi-degree ForeignKey/OneToOne relationships with non-integer primary key |
---|
works for me
comment:2 by , 18 years ago
Component: | Core framework → Database wrapper |
---|
comment:4 by , 18 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
It would be great if someone could take the code example here and turn it into a unit test.
comment:5 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 16 years ago
Has patch: | unset |
---|---|
Keywords: | qsrf added; multi degree foreign key one to one relationship non integer primary key removed |
Needs tests: | unset |
Resolution: | → fixed |
Status: | assigned → closed |
I've attached a regression test for this bug, but I cannot reproduce this as of r10680. I presume it got fixed as part of queryset-refactor.
patch against current trunk