microsoft / mssql-django

The Microsoft Django backend for SQL Server provides a connectivity layer for Django on SQL Server or Azure SQL DB.
Other
324 stars 108 forks source link

[QUESTION]I user mssql-django and how to support chinese?When inserting Chinese using SQL , it was found from the database that it was garbled。 #399

Open HeroZ09 opened 1 month ago

HeroZ09 commented 1 month ago

I user mssql-django and how to support chinese? When inserting Chinese using SQL , it was found from the database that it was garbled。

For example:
**test sql below:**
sql_str= "insert into CHECK_TEST (id,TITLE,AUTHOR) values (6,‘**测试哈哈哈哈哈**’,'hero花')"
cursor.execute(sql_str)
**result below:**
(Decimal('6'), '**???????**', 'hero?', None)

I use django mssql setting below: DATABASES = { "default": { "ENGINE": "mssql", "NAME": "TEST", "USER": "TEST", "PASSWORD": TEST, "HOST": "TEST", } }

mShan0 commented 1 month ago

You will need to change your database's collation to one of the Chinese options.

This doc shows you how to change it: https://learn.microsoft.com/en-us/sql/relational-databases/collations/set-or-change-the-database-collation?view=sql-server-ver16

This gives more information on which collation to choose: https://learn.microsoft.com/en-us/sql/relational-databases/collations/collation-and-unicode-support?view=sql-server-ver16

HeroZ09 commented 1 month ago

You will need to change your database's collation to one of the Chinese options.

This doc shows you how to change it: https://learn.microsoft.com/en-us/sql/relational-databases/collations/set-or-change-the-database-collation?view=sql-server-ver16

This gives more information on which collation to choose: https://learn.microsoft.com/en-us/sql/relational-databases/collations/collation-and-unicode-support?view=sql-server-ver16

OK,I will have a try~ thanks for your support~