Note that there are some explanatory texts on larger screens.

plurals
  1. POpython - Problem storing Unicode character to MySQL with Django
    primarykey
    data
    text
    <p>I have the string </p> <pre><code> u"Played Mirror's Edge\u2122" </code></pre> <p>Which should be shown as </p> <pre><code> Played Mirror's Edge™ </code></pre> <p>But that is another issue. My problem at hand is that I'm putting it in a model and then trying to save it to a database. AKA:</p> <pre><code>a = models.Achievement(name=u"Played Mirror's Edge\u2122") a.save() </code></pre> <p>And I'm getting :</p> <pre><code>'ascii' codec can't encode character u'\u2122' in position 13: ordinal not in range(128) </code></pre> <p>full stack trace (as requested) :</p> <pre><code>Traceback: File "/var/home/ptarjan/django/mysite/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/var/home/ptarjan/django/mysite/yourock/views/alias.py" in import_all 161. types.import_all(type, alias) File "/var/home/ptarjan/django/mysite/yourock/types/types.py" in import_all 52. return modules[type].import_all(siteAlias, alias) File "/var/home/ptarjan/django/mysite/yourock/types/xbox.py" in import_all 117. achiever = self.add_achievement(dict, siteAlias, alias) File "/var/home/ptarjan/django/mysite/yourock/types/base_profile.py" in add_achievement 130. owner = siteAlias, File "/var/home/ptarjan/django/mysite/django/db/models/query.py" in get 304. num = len(clone) File "/var/home/ptarjan/django/mysite/django/db/models/query.py" in __len__ 160. self._result_cache = list(self.iterator()) File "/var/home/ptarjan/django/mysite/django/db/models/query.py" in iterator 275. for row in self.query.results_iter(): File "/var/home/ptarjan/django/mysite/django/db/models/sql/query.py" in results_iter 206. for rows in self.execute_sql(MULTI): File "/var/home/ptarjan/django/mysite/django/db/models/sql/query.py" in execute_sql 1734. cursor.execute(sql, params) File "/var/home/ptarjan/django/mysite/django/db/backends/util.py" in execute 19. return self.cursor.execute(sql, params) File "/var/home/ptarjan/django/mysite/django/db/backends/mysql/base.py" in execute 83. return self.cursor.execute(query, args) File "/usr/lib/pymodules/python2.5/MySQLdb/cursors.py" in execute 151. query = query % db.literal(args) File "/usr/lib/pymodules/python2.5/MySQLdb/connections.py" in literal 247. return self.escape(o, self.encoders) File "/usr/lib/pymodules/python2.5/MySQLdb/connections.py" in string_literal 180. return db.string_literal(obj) Exception Type: UnicodeEncodeError at /import/xbox:bob Exception Value: 'ascii' codec can't encode character u'\u2122' in position 13: ordinal not in range(128) </code></pre> <p>And the pertinant part of the model :</p> <pre><code>class Achievement(MyBaseModel): name = models.CharField(max_length=100, help_text="A human readable achievement name") </code></pre> <p>I'm using a MySQL backend with this in my settings.py</p> <pre><code>DEFAULT_CHARSET = 'utf-8' </code></pre> <p>So basically, how the heck should I deal with all this unicode stuff? I was hoping it would all "just work" if I stayed away from funny character sets and stuck to UTF8. Alas, it seems to not be just that easy.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload