[Answered ]-'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) when i add ForeignKey relation in model

1👍

I found the solution. It’s solved by:

return self.state.encode('utf8')

1👍

If you use Python 2 (and it seems that you do) you should use __unicode__ instead of __str__, for example:

def __unicode__(self):
    return self.state

This will solve your problems with encoding.

In Python 3 however __str__ in the way to go (because the devision between normal strings and unicode strings doesn’t exist in Python 3).

Leave a comment