Modify ↓
Ticket #24 (closed defect: fixed)
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: |
Description
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):
u"""
Версии софта, установленного на компьютере
"""
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()
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

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