0

Recently I've upgraded my Django from 1.6.5 to 1.8.3. I have been using South, so, following tutorial, I've removed South, deleted old migrations and run makemigrations. Then I got error:

[mefioo@ibmed-server kariera_naukowa]$ env/bin/python src/manage.py makemigrations
Migrations for 'editcv':
  0001_initial.py:
    - Create model Adresy
    - Create model Affiliacja
    [...all models from models.py...]
    - Create model ZalRo
    - Add field WszysCz to wlasne
    [...so far only ForeignKeys, but not all of them...]
    - Add field user to adresy
Traceback (most recent call last):
  File "src/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 143, in handle
    self.write_migration_files(changes)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 171, in write_migration_files
    migration_string = writer.as_string()
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 166, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 124, in serialize
    _write(arg_name, arg_value)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 75, in _write
    arg_string, arg_imports = MigrationWriter.serialize(item)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 303, in serialize
    item_string, item_imports = cls.serialize(item)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 377, in serialize
    return cls.serialize_deconstructed(path, args, kwargs)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 268, in serialize_deconstructed
    arg_string, arg_imports = cls.serialize(arg)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 296, in serialize
    value = force_text(value)
  File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/utils/encoding.py", line 102, in force_text
    raise DjangoUnicodeDecodeError(s, *e.args)
django.utils.encoding.DjangoUnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128). You passed in <django.utils.functional.__proxy__ object at 0x268a9d0> (<class 'django.utils.functional.__proxy__'>)

I check out, 0xc3 is à or Ä which I certainly do not use (it does not even exist in polish alphabet).

One of the fk that passed is

wydzial = models.ForeignKey(Wydzial, verbose_name="Wydział")

and it contains polish 'ł', but everything is alright.

What am I missing here?

Mateusz Knapczyk
  • 276
  • 1
  • 2
  • 15
  • Try using unicode strings in your models, e.g. `verbose_name=u"Wydział"`. – Alasdair Jul 15 '15 at 15:33
  • I'm trying to do something with my predecessor code, so there's a mess, most of string got u before them, I'll change rest, but notice that my example without it passed. – Mateusz Knapczyk Jul 15 '15 at 15:35
  • OK, nevermind, I did what you said i it worked, thanks a lot and shame on me. Add it as an answer so I could vote it up and close this thread :) – Mateusz Knapczyk Jul 15 '15 at 15:41

2 Answers2

1

You should avoid problems if you use unicode strings in your models, e.g. verbose_name=u"Wydział".

You might prefer to import unicode_literals from the future library, as recommended by the Django docs. Be careful if adding this to an existing module though!

from __future__ import unicode_literals
Alasdair
  • 298,606
  • 55
  • 578
  • 516
0

Unicode vs python string problem. The Django docs have moved further down the path toward python 3, so they aren't in the habit of warning you anymore. In python2, put a u in front of the string, e.g., u"Wydział". Since you're running 2.7, you can try from __future__ import unicode_literals. Note that this second solution could break some other things in your project.

mitchell_st
  • 116
  • 4