Opened 8 years ago
Last modified 8 years ago
#28309 closed Bug
Migration bug in related_name for ManyToManyField with self — at Version 2
| Reported by: | Ahmed Mohamed | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | 1.11 |
| Severity: | Normal | Keywords: | ManyToManyField self |
| 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 )
The related_name is not set correctly on ManyToManyField when it is related with 'self'. When I use the model name explicitly, it is set correctly.
class Model1(models.Model):
children = models.ManyToManyField('self', blank=True)
class Model2(models.Model):
children = models.ManyToManyField('self', blank=True, related_name='parents')
migrations.CreateModel(
name='Model1',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('children', models.ManyToManyField(blank=True, related_name='_model1_children_+', to='raftprot.Model1')),
],
),
migrations.CreateModel(
name='Model2',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('children', models.ManyToManyField(blank=True, related_name='parents', to='raftprot.Model2')),
],
),
Change History (2)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
| Description: | modified (diff) |
|---|
I've edited the ticket description as I think you meant, please correct it if needed. If the unexpected output in the migration is related_name='_model1_children_+', that's coming from ManyToManyField.contribute_to_class(). I'm uncertain if this is a bug. Can you please clarify?
Note:
See TracTickets
for help on using tickets.
I think there's a mistake in the ticket description. The two
childrenfields in the models are identical.