On Sun, 2006-07-02 at 23:12 +0200, Laurent Rahuel wrote: > Hi, > > I got a serious problem with model inheritance in my Django model. Here's a > sample: > > from django.db import models > > class MPTTTree(models.Model): > created_at = models.DateTimeField(_('creation date'), auto_now_add=True) > updated_at = models.DateTimeField(_('last update date'), auto_now=True) > parent = models.ForeignKey("self", null = True, blank = True) > lhs = models.IntegerField(default=0, db_index = True) > rhs = models.IntegerField(default=0, db_index = True) > level = models.IntegerField(default=0, db_index = True) > > class Test(MPTTTree): > name = models.CharField(_('Name'), maxlength=255) > > I can run python manage.py sql myTest and I get this result : > > BEGIN; > CREATE TABLE "mytest_test" ( > "id" serial NOT NULL PRIMARY KEY, > "created_at" timestamp with time zone NOT NULL, > "updated_at" timestamp with time zone NOT NULL, > "parent_id" integer NULL, > "lhs" integer NOT NULL, > "rhs" integer NOT NULL, > "level" integer NOT NULL, > "name" varchar(255) NOT NULL > ); > CREATE TABLE "mytest_mptttree" ( > "id" serial NOT NULL PRIMARY KEY, > "created_at" timestamp with time zone NOT NULL, > "updated_at" timestamp with time zone NOT NULL, > "parent_id" integer NULL, > "lhs" integer NOT NULL, > "rhs" integer NOT NULL, > "level" integer NOT NULL > ); > > ALTER TABLE "mytest_test" > ADD CONSTRAINT > "parent_id_referencing_mytest_mptttree_id" FOREIGN KEY > ("parent_id") > REFERENCES "mytest_mptttree" ("id"); > > ALTER TABLE "mytest_mptttree" > ADD CONSTRAINT > "parent_id_referencing_mytest_mptttree_id" FOREIGN KEY > ("parent_id") > REFERENCES "mytest_mptttree" ("id"); > > COMMIT; > > I can easely understand the second alter statment but I guess there's a > little > problem with the first one. The constraint should reference "mytest_test" and > not "mytest_mptttree".
Looks like a bug, but since model inheritance does not work in any case it's not something to worry about right at the moment. Even if you fix this your code will not work as you expect it to. Model inheritance does not work with the current trunk. It is in development and will be completed "as soon as possible" (I spent quite a bit of time working on it yesterday again). Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---