Re: recursive relationship foreignkey
On Sun, 2007-08-19 at 18:41 -0400, Francis Lavoie wrote: > Hi, > > I still have this error with null=True . > > model.py: > class Category(models.Model): > name = models.CharField(max_length=36) > description = models.CharField(max_length=200) > parent = models.ForeignKey('self', null=True, blank=True) > > class Admin: > # Admin options go here > pass > > then I did (to reset de database) : python manage.py flush > > and `python manage.py sql myapp` returns : > > BEGIN; > CREATE TABLE `myapp_category` ( > `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, > `name` varchar(36) NOT NULL, > `description` varchar(200) NOT NULL, > `parent_id` integer NULL > ) > ; > ALTER TABLE `myapp_category` ADD CONSTRAINT > parent_id_refs_id_5d9ae1d8600b3d85 FOREIGN KEY (`parent_id`) > REFERENCES `myapp_category` (`id`); That should work perfectly. It's the standard setup for a tree-like model structure. The database table also looks correct. Try creating the models from scratch in a separate project or application and I'll think you'll find it will work. It sounds like there is something going wrong from your earlier failed attempts. Regards, Malcolm -- I don't have a solution, but I admire your problem. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: recursive relationship foreignkey
Hi, I still have this error with null=True . model.py: class Category(models.Model): name = models.CharField(max_length=36) description = models.CharField(max_length=200) parent = models.ForeignKey('self', null=True, blank=True) class Admin: # Admin options go here pass then I did (to reset de database) : python manage.py flush and `python manage.py sql myapp` returns : BEGIN; CREATE TABLE `myapp_category` ( `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` varchar(36) NOT NULL, `description` varchar(200) NOT NULL, `parent_id` integer NULL ) ; ALTER TABLE `myapp_category` ADD CONSTRAINT parent_id_refs_id_5d9ae1d8600b3d85 FOREIGN KEY (`parent_id`) REFERENCES `myapp_category` (`id`); Regards, Francis On dim, 2007-08-19 at 13:02 -0700, olivier wrote: > Hi, > > On 19 août, 21:51, Francis Lavoie <[EMAIL PROTECTED]> wrote: > > I'm trying to implement a recursive relationship with a foreignkey, but I > > failed to make it work. > > If I dont use blank=True, the admin interface doesn't let me add the > > category, otherwise I received the error. > > You need also null = True. > > blank is for django, null is for the backend (btw, OperationalError > are always propagated from the backend). > > Regards, > > Olivier > > > > --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: recursive relationship foreignkey
Hi, On 19 août, 21:51, Francis Lavoie <[EMAIL PROTECTED]> wrote: > I'm trying to implement a recursive relationship with a foreignkey, but I > failed to make it work. > If I dont use blank=True, the admin interface doesn't let me add the > category, otherwise I received the error. You need also null = True. blank is for django, null is for the backend (btw, OperationalError are always propagated from the backend). Regards, Olivier --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---