[Fixed]-Why Django makemigrations detect changes everytime it is run due to accent in help_text/verbose_name attributes?

1👍

It’s recommended to use unicode strings for help_text and verbose_name.

Try marking the string as unicode with the u prefix, then find the previous migration where the verbose name was set as a byte string, and change that to a unicode string as well. Since editing the help_text and verbose_name doesn’t require any schema changes, this should be safe to do.

    migrations.AddField(
        model_name='datedmodel',
        name='created',
        field=models.DateTimeField(default=datetime.datetime(2015, 9, 10, 14, 8, 23, 349990, tzinfo=utc), verbose_name='Créé le', auto_now_add=True),
        preserve_default=False,
    ),

There’s no need for u” prefix in migration file since it has from __future__ import unicode_literals.

Then, when you rerun makemigrations, Django will hopefully say ‘no changes detected’.

đŸ‘€Alasdair

0👍

Appending .encode('utf-8') prevent the error but makemigrations still detect changes each time it is run.

class Checkpoint(models.Model):
    name = models.CharField(max_length=128, help_text=_('Nom du repĂšre/checkpoint'.encode('utf-8')))
    passed = models.BooleanField(default=False, help_text=_('Le checkpoint a t-il était validé?'.encode('utf-8')))
    site = models.ForeignKey('Site', null=True, help_text=_('Entité concernée par le checkpoint'.encode('utf-8')))

Leave a comment