Opened 4 years ago

Closed 4 years ago

#32294 closed Bug (fixed)

fields.E305 is raised on ManyToManyFields with related_name='+' in models in different apps but with the same name.

Reported by: Aleksey Ruban Owned by: Manav Agarwal
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Aleksey Ruban)

Django raises an error during creation a db migration if two models with the same name refer to the same model in m2m field. related_name='+' or 'foo+' don't impact anything.
In some my project there are 50 apps and almost each one has a model with the same name. So I have to come up with a related name and write it in for each m2m field.
Just try to make a migration for my test project
https://github.com/rafick1983/django_related_name_bug

Change History (7)

comment:1 by Aleksey Ruban, 4 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 4 years ago

Summary: related_name='+' doesn't work for ManyToMany fieldsfields.E305 is raised on ManyToManyFields with related_name='+' in models in different apps but with the same name.
Triage Stage: UnreviewedAccepted

Thanks for the report. It looks that app_label is missing in ManyToManyField.contribute_to_class():

self.remote_field.related_name = "_%s_%s_%s_+" % (cls._meta.app_label, cls.__name__.lower(), name)

comment:3 by Mariusz Felisiak, 4 years ago

Easy pickings: set

comment:4 by Manav Agarwal, 4 years ago

Owner: changed from nobody to Manav Agarwal
Status: newassigned

comment:5 by Mariusz Felisiak, 4 years ago

Has patch: set

comment:6 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In a9a7421a:

Fixed #32294 -- Prevented ManyToManyField's hidden related name collisions between apps.

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