Ticket #24 (closed defect: fixed)

Opened 7 years ago

Last modified 7 years ago

migrations do not respect source files encoding, causing SyntaxError: Non-ASCII character in generated migrations

Reported by: shamardin@… Owned by: andrew
Priority: critical Milestone:
Component: commands Version:
Keywords: Cc:


If you have non-latin1 text in your models, you will see troubles like these trying to perform migrations:

[shamardin@abbot server]$ ./manage.py startmigration control --initial
Creating migrations directory at '/home/shamardin/advertizer/soft/server/cvg/control/migrations'...
Created 0001_initial.py.
[shamardin@abbot server]$ ./manage.py migrate control --db-dry-run
  File "/home/shamardin/advertizer/soft/server/cvg/control/migrations/0001_initial.py", line 66
SyntaxError: Non-ASCII character '\xd0' in file /home/shamardin/advertizer/soft/server/cvg/control/migrations/0001_initial.py on line 66, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

Proposed solution would be to check for encoding tags in models.py and add them automatically to generated migrations. In this particular example simply adding

# -*- encoding: utf-8 -*-

as a first line to the generated 0001_initial.py solves the problem

Excerpt from the models.py to reproduce the problem:

# -*- encoding: utf-8 -*-

class SoftwareComponent(models.Model):
    Версии софта, установленного на компьютере
    name = models.CharField(u'Пакет', max_length=255, blank=False, null=False, unique=False)
    version = models.CharField(u'Версия', max_length=255, blank=False, null=False, unique=False)

    def component(self):
        return u'%s-%s' % (self.name, self.version)

    def __unicode__(self):
        return self.component()

Change History

comment:1 Changed 7 years ago by andrew

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in [124]. Sorry about the delay there :)

Note: See TracTickets for help on using tickets.