Opened 8 years ago
Last modified 8 years ago
#28920 closed Bug
AlterModelManagers migration is generated for all Models with custom Managers, which is not compatible with Django 1.8 — at Initial Version
| Reported by: | Michał Bońkowski | Owned by: | nobody | 
|---|---|---|---|
| Component: | Migrations | Version: | 1.11 | 
| Severity: | Normal | Keywords: | |
| Cc: | Sjoerd Job Postmus | Triage Stage: | Unreviewed | 
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
We have a Model and a default_manager with a custom name:
class MyManager(models.Manager):
    use_in_migrations = False
class MyModel(models.Model):
    my_field = models.BooleanField()
    class Meta:
        default_manager_name = 'my_objects'
    my_objects = MyManager()
This creates a migration with a default manager though no manager is marked with use_in_migrations = True.
class Migration(migrations.Migration):
    operations = [
        migrations.CreateModel(
            name='MyModel',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('my_field', models.BooleanField()),
            ],
            options={
                'default_manager_name': 'my_objects',
            },
            managers=[
                ('my_objects', django.db.models.manager.Manager()),
            ],
        ),
    ]
According to https://code.djangoproject.com/ticket/26643#comment:5, we should not get this manager added to the state.
After some investigation, we can see that manager with any other name than objects will be added to the migration: https://github.com/django/django/blob/1.11.8/django/db/migrations/state.py#L537.