﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29521	Infinite migrations without changes on code when Choices are store in a dictionary	Roberto Fernandez Diaz	nobody	"I have this code on my model


{{{
class Alcance(models.Model):
    # CHOICES
    CONCEJO = 'CO'
    PROVINCIA = 'PR'
    PAIS = 'PA'

    ZONA_AFECTADA_OPTIONS = {
        (CONCEJO, 'concejo'),
        (PROVINCIA, 'provincia'),
        (PAIS, 'pais')
    }

    # DATABASE FIELDS
       ...
       zona_afectada = models.CharField(max_length=2, choices=ZONA_AFECTADA_OPTIONS, default='CO')
}}}

The problem is that each time I execute the command, manage.py makemigrations

It always detect a change on this part of the code, generating always a new migration file

Example : 

accounts\migrations\0004_auto_20180610_1356.py

{{{
# Generated by Django 2.0 on 2018-06-10 13:56

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('accounts', '0003_auto_20180602_2019'),
    ]

    operations = [
        migrations.AlterField(
            model_name='alcance',
            name='zona_afectada',
            field=models.CharField(choices=[('PA', 'pais'), ('PR', 'provincia'), ('CO', 'concejo')], default='CO', max_length=2),
        ),
    ]

}}}


accounts\migrations\0005_auto_20180624_0126.py


{{{
# Generated by Django 2.0 on 2018-06-23 23:26

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('accounts', '0004_auto_20180610_1356'),
    ]

    operations = [
        migrations.AlterField(
            model_name='alcance',
            name='zona_afectada',
            field=models.CharField(choices=[('CO', 'concejo'), ('PR', 'provincia'), ('PA', 'pais')], default='CO', max_length=2),
        ),
    ]
}}}

accounts\migrations\0006_auto_20180624_1205.py

{{{
# Generated by Django 2.0 on 2018-06-24 10:05

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('accounts', '0005_auto_20180624_0126'),
    ]

    operations = [
        migrations.AlterField(
            model_name='alcance',
            name='zona_afectada',
            field=models.CharField(choices=[('PA', 'pais'), ('CO', 'concejo'), ('PR', 'provincia')], default='CO', max_length=2),
        ),
    ]
}}}

And so on...

As you can see the problem is due to the order in which the choices appear, that seems to be order randomly.

This is done without me changing the order of the elements of the dictionary or anything on the code that I show on the top.



"	Bug	closed	Migrations	2.0	Normal	invalid	makemigrations migration choices distionary		Unreviewed	0	0	0	0	0	0
