On Wed, Aug 20, 2008 at 3:31 AM, anonymous <[EMAIL PROTECTED]> wrote:

>
> Hello all,
>
> I get the following error:
> ----
> In [2]: from myapp.models import *
>
> In [3]: Mymodel.objects.all()
> Out[3]:
> ---------------------------------------------------------------------------
> UnicodeDecodeError                        Traceback (most recent call
> last)
>
> [snip]



> /usr/lib/python2.5/site-packages/django/db/models/base.pyc in
> __repr__(self)
>    242
>    243     def __repr__(self):
> --> 244         return smart_str(u'<%s: %s>' %
> (self.__class__.__name__, unicode(self)))
>    245
>    246     def __str__(self):
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 6: ordinal not in range(128)
> ----


Have you defined a __unicode__ method for your model?  If yes, what does it
look like?  Also are you using a binary collation?


> In Mymodel table there are strings with accents like "construcción".
> This table have been created by syncdb as " DEFAULT CHARSET=latin1;".
> I've probed to alter the table to  " DEFAULT CHARSET=utf8" but still
> get the same error.
>

FYI it wasn't necessary to change the charset from latin1, latin1 works fine
so long as you do not need to store data that cannot be represented in that
charset.  MySQL will convert to/from utf8 based on the fact that Django sets
to connection charset to utf8.


>
> In the settings.py file  I have:
> DATABASE_OPTIONS = {'use_unicode': True, 'charset': 'utf8',
> "init_command": "SET storage_engine=INNODB", "init_command": "set
> names utf8","init_command": "SET character_set_database=utf8",
> "init_command": "SET character_set_client=utf8"
> }


Also most of these settings in DATABASE_OPTIONS are unnecessary.  The only
one that you really need if it is not your database default storage engine
is "SET storage_engine=InnoDB".

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to