Modelのverbose_name(その2)


UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

このエラーが出るのは、unicode文字列のデフォルトのエンコーディングが(Python自体に)指定されていないからのようです。
C:\Python2.4\Lib\sitecustomize.py を次の内容で作成して、デフォルトを'utf8'に変更してみました。詳しくはこちらを参照


import sys
sys.setdefaultencoding('utf-8')

とりあえず、元のエラーは回避できたようですが、今度はMySQLのところでエラーが出るようになってしまいました。


Traceback (most recent call last):
File "manage.py", line 11, in ?
execute_manager(settings)
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\core\manage
ment.py", line 1319, in execute_manager
execute_from_command_line(action_mapping, argv)
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\core\manage
ment.py", line 1243, in execute_from_command_line
action_mapping[action]()
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\core\manage
ment.py", line 491, in syncdb
app=app, created_models=created_models)
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\dispatch\di
spatcher.py", line 347, in send
sender=sender,
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\dispatch\ro
bustapply.py", line 47, in robustApply
return receiver(*arguments, **named)
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\contrib\aut
h\management.py", line 29, in create_permissions
defaults={'name': name, 'content_type': ctype})
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\db\models\m
anager.py", line 70, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\db\models\q
uery.py", line 240, in get_or_create
obj.save()
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\db\models\b
ase.py", line 203, in save
','.join(placeholders)), db_values)
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\db\backends
\util.py", line 12, in execute
return self.cursor.execute(sql, params)
File "C:\Python24\lib\site-packages\django-0.95.1-py2.4.egg\django\db\backends
\mysql\base.py", line 35, in execute
return self.cursor.execute(sql, params)
File "C:\Python24\lib\site-packages\MySQLdb\cursors.py", line 163, in execute
r = self._query(query % self.connection.literal(args))
File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 182, in lite
ral
return self.escape(o, self.converter)
File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 150, in unic
ode_literal
return self.literal(u.encode(self.charset))
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 8-9: ord
inal not in range(256)