#33515 closed Bug (fixed)
ManyToManyField to lowercased swappable setting causes generating infinite migrations.
| Reported by: | Chris Lee | Owned by: | Mariusz Felisiak |
|---|---|---|---|
| Component: | Migrations | Version: | 4.0 |
| Severity: | Release blocker | Keywords: | M2M migration user manytomany |
| Cc: | Simon Charette, David Wobrock | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
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.
# 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), ), ]
Change History (6)
comment:1 by , 4 years ago
| Summary: | Adding ManyToMany field using setttings.AUTH_USER_MODEL creates unnecessary migrations → Adding ManyToMany field using custom User model (AbstractUser) creates unnecessary migrations |
|---|
comment:2 by , 4 years ago
| Cc: | added |
|---|---|
| Severity: | Normal → Release blocker |
| Summary: | Adding ManyToMany field using custom User model (AbstractUser) creates unnecessary migrations → ManyToManyField to lowercased swappable setting causes generating infinite migrations. |
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 4 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
Thanks for the report!
Lowercased
AUTH_USER_MODEL = 'accounts.user'is crucial to reproduce this issue.Regression in 43289707809c814a70f0db38ca4f82f35f43dbfd.