Opened 7 years ago

Last modified 7 years ago

#28309 closed Bug

Migration bug in related_name for ManyToManyField with self — at Initial Version

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

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, related_name='parents')

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 (0)

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