#33515: Adding ManyToMany field using setttings.AUTH_USER_MODEL creates
unnecessary
migrations
-------------------------------------+-------------------------------------
Reporter: Chris Lee | Owner: nobody
Type: Bug | Status: new
Component: | Version: 4.0
Migrations | Keywords: M2M migration user
Severity: Normal | manytomany
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
If I create a custom user model that extends `AbstractUser` and then try
to add a `ManyToManyField` that references this custom User model, django
keeps making the same `AlterField` migration over and over again
unnecessarily. I've attached a Git repository that I used to reproduce
this issue with very simple code. You can see the two erroneous migrations
after the initial migration. If I use the built in user, there is no
issue. It seems to appear once I extend `AbstractUser`.
Git repository: https://github.com/SentientClee/django-bug-reproduction
Here is the `accounts` app `model.py` code.
{{{#!python
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
pass
class Test(models.Model):
members = models.ManyToManyField(settings.AUTH_USER_MODEL)
}}}
Here is one of the erroneous migrations. Notice it depends on
`0002_alter_test_members` which is an erroneous migrations file that looks
just like this one.
{{{#!python
# Generated by Django 4.0.2 on 2022-02-15 01:33
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0002_alter_test_members'),
]
operations = [
migrations.AlterField(
model_name='test',
name='members',
field=models.ManyToManyField(to=settings.AUTH_USER_MODEL),
),
]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33515>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.8d135b60593bc6780d22c9bbab8ac389%40djangoproject.com.