Note that there are some explanatory texts on larger screens.

plurals
  1. POSpecial Characters and Encoding
    primarykey
    data
    text
    <p>Although there are hundreds of questions of this kind, there isn't an appropriate answer helping me to understand and solve my problem.</p> <p>I wanted to switch from a SQLite database to a MySQL database in my django installation. Everything works fine, and I can still add special characters via the admin interface, however, it raises an encoding error when using the <code>save()</code> method on user generated input.</p> <pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 5: ordinal not in range(128) </code></pre> <p>Any hints?</p> <p><strong>edit</strong></p> <p>Database Character Set:</p> <pre><code>mysql&gt; show variables like "character_set_database"; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | character_set_database | utf8 | +------------------------+-------+ 1 row in set (0.00 sec) mysql&gt; show variables like "collation_database"; +--------------------+-----------------+ | Variable_name | Value | +--------------------+-----------------+ | collation_database | utf8_general_ci | +--------------------+-----------------+ 1 row in set (0.00 sec) </code></pre> <p>Full Traceback:</p> <pre><code>Traceback (most recent call last): File "myscript.py", line 48, in &lt;module&gt; add_categories_to_db() File "myscript.py", line 38, in add_categories_to_db cat.save() File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 545, in save force_update=force_update, update_fields=update_fields) File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 573, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 654, in _save_table result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 687, in _do_insert using=using, raw=raw) File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 232, in _insert return insert_query(self.model, objs, fields, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1511, in insert_query return query.get_compiler(using=using).execute_sql(return_id) File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 898, in execute_sql cursor.execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 69, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute return self.cursor.execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 124, in execute return self.cursor.execute(query, args) File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 159, in execute query = query % db.literal(args) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 264, in literal return self.escape(o, self.encoders) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 197, in string_literal return db.string_literal(obj) UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 5: ordinal not in range(128) </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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