Django model.charfield - unicode or not unicode
I transferred the project to another computer and I get an error when starting the view.
I am getting some information about a model and want to store it in XML using XMLGenerator.
On one computer it works fine, type()
model.charField()
returns "unicode"
On new computer it didn't work, type()
model.charField()
returns "str"
The work computer has Python 2.7.2
A non-working computer has Python 2.5.2
So, on a non-working computer, I didn't get a unicode that XMLGenerator can handle. I tried to solve the problem by running .decode ("utf-8") on the line served by the model and it worked.
But how can I find out what the encoding of the string is? I already guessed that it has the same encoding as in the database, but am I right?
thinks Martin
source to share
Could you check your mysql collation settings? if they are the same? from django doc: "In many cases this default will not be a problem. However, if you really want to compare case to case in a specific column or table, you must change the column or table to use utf8_bin collation. The main thing to know about in In this case, if you are using MySQLdb 1.2.2, the database backend in Django then returns bytes (instead of unicode strings) for any character fields it receives from the database. " see django doc mapping settings
source to share