Reputation: 49
I want build a blog with Python 2.7 and Django 1.7.8.
When I use Django,I keep getting an error: UnicodeDecodeError
.
The relevant code is:
#coding: utf-8
from django.db import models
class Entry(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
publish = models.BooleanField(default=False)
And ./manage.py makemigrations
get an error:
Migrations for 'blog':
0001_initial.py:
- Create model Entry
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/commands/makemigrations.py", line 124, in handle
self.write_migration_files(changes)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/commands/makemigrations.py", line 143, in write_migration_files
migrations_directory = os.path.dirname(writer.path)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/db/migrations/writer.py", line 222, in path
return os.path.join(basedir, self.filename)
File "/usr/lib/python2.7/posixpath.py", line 80, in join
path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 10: ordinal not in range(128)
I don't see what's going wrong, any idea? I already add coding:utf-8
in top of code
Upvotes: 3
Views: 1020
Reputation: 1015
it looks like it fails when joining the path?
maybe you have folder names that can't be converted to ascii?
also , consider editing the file that is having the error? maybe add a print statement just before the line that fails that shows what is trying to be joined?
edit the file mentioned below, add the print statement to see what is trying to be joined?
File "/usr/lib/python2.7/posixpath.py", line 80, in join
path += '/' + b
Upvotes: 1
Reputation: 1015
do you have data in the models already? if so, i am guessing you have some bad characters in there. do you have a unicode or str method defined on the models? if so, i suggest using them in a try statement of sorts like this:
def __str__():
try:
return "%s" % self.title
except:
return "%s" % self.pk
when you see only the PK, you will know that your 'title' field has bad data. extend this to include whichever fields you want to display, not just title.
Upvotes: 1