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 Alex Gaynor)

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

Change History (2)

comment:1 by simon_gray99, 15 years ago

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:

Error: Error: idj couldn't be reset. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlreset idj'. That's the SQL this command wasn't able to run.
The full error: relation "persons_idols" does not exist

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?

comment:2 by Alex Gaynor, 15 years ago

Description: modified (diff)

Please use the preview button.

Note: See TracTickets for help on using tickets.
Back to Top