Tuesday, May 3, 2016

Re: Integer field choice list keeps triggering migration

On 3/05/2016 4:58 PM, jorrit787@gmail.com wrote:
> I have the following model and choice list:
>
> BTW_TARIEF_CHOICES = {
> (1, '6%'),
> (2, '21%'),
> (3, '0%'),
> }
>

Migrations see these changes as model changes. The model does change
because it gets actual new choices in its definition.

At any particular revision of your software there will be or might be
different possible choices. So that means you can roll back to a
different revision and get the correct choices for that revision.

Mike

>
> class FactuurItem(models.Model):
> naam = models.CharField(max_length=100)
> factuur_naam = models.CharField(max_length=100)
> eenheid = models.CharField(max_length=10)
> prijs = models.DecimalField(max_digits=6, decimal_places=2)
> btw_tarief = models.IntegerField(choices=BTW_TARIEF_CHOICES, default=2)
>
> class Meta:
> ordering = ['naam']
>
> def __str__(self):
> return self.naam
>
>
> Makemigrations creates a migration for the btw_tarief field every time I
> run it, even though the field hasn't changed. It shows up in every
> migration file that has been created since I added the field to the
> model. The only thing that seems different in every migration file is
> that the order of BTW_TARIEF_CHOICES is randomized:
>
> class Migration(migrations.Migration):
>
> dependencies = [
> ('common', '0021_auto_20160503_0849'),
> ]
>
> operations = [
> migrations.AlterField(
> model_name='factuuritem',
> name='btw_tarief',
> field=models.IntegerField(choices=[(1, '6%'), (3, '0%'), (2, '21%')], default=2),
> ),
> ]
>
>
> class Migration(migrations.Migration):
>
> dependencies = [
> ('common', '0020_auto_20160502_1656'),
> ]
>
> operations = [
> migrations.AlterField(
> model_name='factuuritem',
> name='btw_tarief',
> field=models.IntegerField(choices=[(2, '21%'), (3, '0%'), (1, '6%')], default=2),
> ),
> ]
>
>
> class Migration(migrations.Migration):
>
> dependencies = [
> ('common', '0019_auto_20160502_1604'),
> ]
>
> operations = [
> migrations.AlterField(
> model_name='factuuritem',
> name='btw_tarief',
> field=models.IntegerField(choices=[(1, '6%'), (3, '0%'), (2, '21%')], default=2),
> ),
> ]
>
>
> And so on... This happens on Django 1.9.5 and 1.9.6 .
>
> Any ideas why this might be happening?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/88e66c3f-6ebe-4a14-93fe-1b865b712e61%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/88e66c3f-6ebe-4a14-93fe-1b865b712e61%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2691475d-0870-d99e-1611-b14cf72f14e2%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment