﻿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
30350	Migration re-add check constraint continuously when check condition contains a range object.	Sigurd Ljødal	Florian Apolloner	"A `CheckConstraint` with a `Q(x__in=range(y, z))` condition is repeatedly deleted and re-added when running `makemigrations`.


{{{#!python
models.CheckConstraint(
    check=models.Q(month__in=range(1, 13)),
    name='check_valid_month',
)
}}}

The generated migration looks like this, so I suspect that the issue is because the range is converted into a tuple:

{{{#!python
    operations = [
        migrations.RemoveConstraint(
            model_name='monthlybudget',
            name='check_valid_month',
        ),
        migrations.AddConstraint(
            model_name='monthlybudget',
            constraint=models.CheckConstraint(check=models.Q(month__in=(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)), name='check_valid_month'),
        ),
    ]
}}}

A sample project with this issue can be found here:
https://github.com/ljodal/djangocon-eu-2019

I'm open to fixing this issue myself, but I would like to clarify what would be a correct fix to this issue. I see at least two possible solutions, maybe three:
 1. Keep the `range` method call in the generated migration file
 2. Disallow using ranges in check constraints
 3. (At least on PostgreSQL, we could use a range expression in the database too.)"	Bug	closed	Migrations	2.2	Release blocker	fixed		Ian Foote	Ready for checkin	0	0	0	0	0	0
