Opened 19 years ago

Closed 18 years ago

Last modified 17 years ago

#129 closed defect (fixed)

Multiple ManyToManyField fields with same "to" reference tries to create duplicate tables

Reported by: jason@… Owned by: Adrian Holovaty
Component: Metasystem Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Revsion 257 added support for adding multiple ManyToManyField fields with the same "to" class on the same class. I've tried adding two fields where one has an explicit rel_name option but running "django-admin.py sql myapp" is showing two CREATE TABLE statements with the same table name.

I think I've tracked the problem down to the get_m2m_db_table method in the ManyToManyField class in core/meta.py but I don't understand the code base enough yet to try to fix it.

It looks like the code is returning the name as myapp_fromname_toname but I'd expect the name of the many-to-many table to be myapp_relname when the rel_name option is specified.

I'm using the MySQL database engine but I don't think that has any bearing on this problem.

Change History (5)

comment:1 by Adrian Holovaty, 19 years ago

Resolution: worksforme
Status: newclosed

The docs are sketchy on this, but the solution is to set rel_name and related_name.

Example:

        meta.ManyToManyField(Category, verbose_name="Categories to include"),
        meta.ManyToManyField(Category, name="excluded_categories", rel_name="excluded_category", related_name='excluded_section', verbose_name="Categories to exclude"),

comment:2 by jason@…, 19 years ago

Resolution: worksforme
Status: closedreopened

Using your example, I was able to get it to work. Setting rel_name and related_name doesn't have any effect on the generated table name. Setting name does have an affect on the table name, though.

I reopened the ticket just to confirm that this is what you intended since it conflicts with your comment.

comment:3 by Adrian Holovaty, 19 years ago

Status: reopenednew

comment:4 by Adrian Holovaty, 19 years ago

Status: newassigned

comment:5 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: assignedclosed

I believe this is fixed in the new trunk.

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