0

I've a django app with a mysql database. We are trying to launch the Arabic version of the website. The current language is English. For some reason when I write something in Arabic through the admin panel and click save, it shows ???? instead of the Arabic word i wrote. I've no idea how to fix it.

I followed this post and added #-*- coding: utf-8 -*- to my admin.py, models.py and views.py files. It didn't work

I also added these to my.conf mysql file to change the character set. It didn't work either.

character-set-server=utf8
collation-server=utf8_unicode_ci
init_connect='set collation_connection = utf8_unicode_ci;'
Community
  • 1
  • 1
James L.
  • 1,123
  • 21
  • 50

2 Answers2

1

Did you checked encoding of your database and your tables? If they are not in utf-8, you might try to convert it.

ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE tablename CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `db_table_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

(code is from here: Save Data in Arabic in MySQL database)

Community
  • 1
  • 1
Paul
  • 5,868
  • 8
  • 36
  • 54
1

What probably happened:

  • you had utf8-encoded data (good)
  • SET NAMES latin1 was in effect (default, but wrong)
  • the column was declared CHARACTER SET latin1 (default, but wrong)

Please provide SHOW CREATE TABLE so we can formulate an ALTER to fix the columns.

Django needs client_encoding: 'UTF8'; sorry, I don't know where that goes.

Rick James
  • 122,779
  • 10
  • 116
  • 195