A
A
Andrei Ramanchyk2018-10-26 12:30:24
PostgreSQL
Andrei Ramanchyk, 2018-10-26 12:30:24

Why in django 1.9 do I get migrations when I makemigrations that I don't expect?

in the model i have a field

currency = models.CharField(_('currency'), choices=[(x, x) for x in settings.CURRENCIES], max_length=3)

I did not rule this model, but I ruled another where I changed the unique_together attribute in the META parameter.
Naturally, I expected that I would have a migration to change the uniqueness, but I additionally got knocked out
....
migrations.AlterField(
            model_name='mymodel',
            name='currency',
            field=models.CharField(choices=[('USD', 'USD'), ('JPY', 'JPY')], max_length=3, verbose_name='currency'),
        ),
.....

Choices are in setting.py. There are a lot of migrations in the project that are not mine, but it is my migration that leads to such consequences.
Prompt where to dig!!! I honestly don't see the obvious things.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Malyarov, 2018-10-26
@Konstantin18ko

These are internal migrations - django. Users, Groups, Permissions

A
Alexey Guest007, 2018-10-30
@Guest007

The value of the c field choicesis formed statically at the migration stage. It's just that at this moment your list comprehension is interpreted, a list is formed and the field is updated with it. The fact that nothing has changed since the last time during the migration is not tracked.
If you do not want to see this migration every time - set the list of currencies statically, by hand.
If it is supposed to change "on the fly" - improve the connection with the currency reference (via ForeignKeyor ManyToManyField)
Well, or each time correct the migration before applying it, deleting this field.
Or delete this migration if changing this field in it is the only operation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question