Is this the right place to ask about what looks to be a bug? If not,
sorry....

If so, the following code will cause generation of SQL that is missing
constraints:
-----------------------------------------------------------------------------------
# in project 'test'
from django.db.models import (
    Model, ForeignKey
    )

# Create your models here.


class Retrieval( Model ):
    pass

class Abs( Model ):
    retrieval = ForeignKey( Retrieval )
    invalidatedby = ForeignKey(
        Retrieval, related_name = 'invalidates', null = True )


class A1( Abs ):
    pass

class A2( Abs ):
    pass
----------------------------------------------------------------------------------
C:\...>python manage.py sqlall test
BEGIN;
CREATE TABLE "test_a1" (
    "id" serial NOT NULL PRIMARY KEY,
    "retrieval_id" integer NOT NULL,
    "invalidatedby_id" integer NULL
);
CREATE TABLE "test_abs" (
    "id" serial NOT NULL PRIMARY KEY,
    "retrieval_id" integer NOT NULL,
    "invalidatedby_id" integer NULL
);
CREATE TABLE "test_retrieval" (
    "id" serial NOT NULL PRIMARY KEY
);
ALTER TABLE "test_abs" ADD CONSTRAINT
"retrieval_id_referencing_test_retrieval_id" FOREIGN KEY (
"retrieval_id") REFERENCES "test_retrieval" ("id");
ALTER TABLE "test_abs" ADD CONSTRAINT
"invalidatedby_id_referencing_test_retrieval_id" FOREIGN K
EY ("invalidatedby_id") REFERENCES "test_retrieval" ("id");
CREATE TABLE "test_a2" (
    "id" serial NOT NULL PRIMARY KEY,
    "retrieval_id" integer NOT NULL REFERENCES "test_retrieval" ("id"),
    "invalidatedby_id" integer NULL REFERENCES "test_retrieval" ("id")
);
CREATE INDEX test_a1_retrieval_id ON "test_a1" ("retrieval_id");
CREATE INDEX test_a1_invalidatedby_id ON "test_a1"
("invalidatedby_id");
CREATE INDEX test_abs_retrieval_id ON "test_abs" ("retrieval_id");
CREATE INDEX test_abs_invalidatedby_id ON "test_abs"
("invalidatedby_id");
CREATE INDEX test_a2_retrieval_id ON "test_a2" ("retrieval_id");
CREATE INDEX test_a2_invalidatedby_id ON "test_a2"
("invalidatedby_id");
COMMIT;
-----------------------------------------------------------------------------------
Note that constaints of for test_a1 are missing.

NB whether and how this bug happens is highly senstive to the class
names in models.py -- presumably because somewhere the module
dictionary is being iterated through and whether something is a
"forward reference" requiring ALTER TABLEs or a "backward reference"
just requiring constraints in the delcarations depends on the hash
codes for the class names.

But the bottom line is that only one set of ALTER TABLESs can be
generated in this situation, where we might need more than one.

Thanks for help or tips if I'm doing something wrong

- Shaun

X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.11.53.63 with SMTP id b63mr87424cwa;
        Sat, 20 May 2006 10:44:03 -0700 (PDT)
X-Google-Token: X8HwWQwAAAAoX1k1IW-f1ZpjSIYTko_F
Received: from 66.92.72.228 by i40g2000cwc.googlegroups.com with HTTP;
        Sat, 20 May 2006 17:44:03 +0000 (UTC)
From: "shaunc" <[EMAIL PROTECTED]>
To: "Django developers" <[email protected]>
Subject: bug? missing foreign key constraints in SQL
Date: Sat, 20 May 2006 10:44:03 -0700
Message-ID: <[EMAIL PROTECTED]>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) 
Gecko/20060426 Firefox/1.5.0.3,gzip(gfe),gzip(gfe)
Mime-Version: 1.0
Content-Type: text/plain

Is this the right place to ask about what looks to be a bug? If not,
sorry....

If so, the following code will cause generation of SQL that is missing
constraints:
-----------------------------------------------------------------------------------
# in project 'test'
from django.db.models import (
    Model, ForeignKey
    )

# Create your models here.


class Retrieval( Model ):
    pass

class Abs( Model ):
    retrieval = ForeignKey( Retrieval )
    invalidatedby = ForeignKey(
        Retrieval, related_name = 'invalidates', null = True )


class A1( Abs ):
    pass

class A2( Abs ):
    pass
----------------------------------------------------------------------------------
C:\...>python manage.py sqlall test
BEGIN;
CREATE TABLE "test_a1" (
    "id" serial NOT NULL PRIMARY KEY,
    "retrieval_id" integer NOT NULL,
    "invalidatedby_id" integer NULL
);
CREATE TABLE "test_abs" (
    "id" serial NOT NULL PRIMARY KEY,
    "retrieval_id" integer NOT NULL,
    "invalidatedby_id" integer NULL
);
CREATE TABLE "test_retrieval" (
    "id" serial NOT NULL PRIMARY KEY
);
ALTER TABLE "test_abs" ADD CONSTRAINT
"retrieval_id_referencing_test_retrieval_id" FOREIGN KEY (
"retrieval_id") REFERENCES "test_retrieval" ("id");
ALTER TABLE "test_abs" ADD CONSTRAINT
"invalidatedby_id_referencing_test_retrieval_id" FOREIGN K
EY ("invalidatedby_id") REFERENCES "test_retrieval" ("id");
CREATE TABLE "test_a2" (
    "id" serial NOT NULL PRIMARY KEY,
    "retrieval_id" integer NOT NULL REFERENCES "test_retrieval" ("id"),
    "invalidatedby_id" integer NULL REFERENCES "test_retrieval" ("id")
);
CREATE INDEX test_a1_retrieval_id ON "test_a1" ("retrieval_id");
CREATE INDEX test_a1_invalidatedby_id ON "test_a1"
("invalidatedby_id");
CREATE INDEX test_abs_retrieval_id ON "test_abs" ("retrieval_id");
CREATE INDEX test_abs_invalidatedby_id ON "test_abs"
("invalidatedby_id");
CREATE INDEX test_a2_retrieval_id ON "test_a2" ("retrieval_id");
CREATE INDEX test_a2_invalidatedby_id ON "test_a2"
("invalidatedby_id");
COMMIT;
-----------------------------------------------------------------------------------
Note that constaints of for test_a1 are missing.

NB whether and how this bug happens is highly senstive to the class
names in models.py -- presumably because somewhere the module
dictionary is being iterated through and whether something is a
"forward reference" requiring ALTER TABLEs or a "backward reference"
just requiring constraints in the delcarations depends on the hash
codes for the class names.

But the bottom line is that only one set of ALTER TABLESs can be
generated in this situation, where we might need more than one.

Thanks for help or tips if I'm doing something wrong

- Shaun


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to