Opened 15 years ago
Last modified 15 years ago
#11738 closed
many2many recursive relationship do not work in DJ 1.1 - second problem — at Version 2
Reported by: | simon_gray99 | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.1 |
Severity: | Keywords: | many2many recursive missing tables | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
According to the page at:
http://www.djangoproject.com/documentation/models/m2m_recursive/
All that is required to produce a recursive many2many is the following code:
from django.db import models class Person(models.Model): name = models.CharField(max_length=20) friends = models.ManyToManyField('self') idols = models.ManyToManyField('self', symmetrical=False, related_name='stalkers') def __unicode__(self): return self.name
When I try this exact same code in my application,
I get an immediate complaint that the table 'persons_idols' does not exist.
If I CREATE this table manually then things are OK but the documentation state that DJ is supposed to handle creating this
table when the 'through' flag is NOT used... it doesn't!
Please advise
In addition, if I CREATE the table needed in my model (in this case 'persons_idols')
then I am unable to create a test database with the following error:
even although I had created the table. Examining the SQL in more detail, I find that it is trying to DROP the table before it has created it... and therefore failing, of course. WTF?
So it seems like either I have to create the tables by hand in order to get the model to work, and give up automated testing,
or I have to skip recursive many2many links completely and somehow find another way through... :(
Please can someone point me in an effective direction for a solution?