How to set the encoding for the tables char columns in django

0 votes

All fields that are supposed to store some strings are supposed to be in UTF-8, however, when I run

manage.py syncdb

all respective columns are created with cp1252 character set (where did it get that -- I have no idea) and I have to manually update every column...

Is there a way to tell Django to create all those columns with UTF-8 encoding in the first place?

Jun 24, 2020 in Python by kartik
• 37,520 points
2,764 views

1 answer to this question.

0 votes

Hello @kartik,

Django does not specify charset and collation in CREATE TABLE statements. Everything is determined by database charset. Doing ALTER DATABASE ... CHARACTER SET utf8 COLLATE utf8_general_ci before running syncdb should help.

For connection, Django issues SET NAMES utf8 automatically, so you don't need to worry about default connection charset settings.

Hope this works!!
Thank You!

answered Jun 24, 2020 by Niroj
• 82,840 points

Related Questions In Python

0 votes
0 answers

how do i install django in my system for the project?

can you tell me the procedure for ...READ MORE

May 3, 2019 in Python by Waseem
• 4,540 points
716 views
0 votes
1 answer

How do I run a set of code for all the requests in Flask?

Hi, You can use dedicated hooks(decorators) called before ...READ MORE

answered Jun 21, 2019 in Python by Shabnam
• 930 points
810 views
0 votes
1 answer

How to set other Inline title in Django Admin?

Hii @kartik, You need to set the values ...READ MORE

answered Jun 29, 2020 in Python by Niroj
• 82,840 points
2,460 views
0 votes
1 answer

How to set up a PostgreSQL database in Django?

Hello @kartik, Steps that I use: - sudo apt-get ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,840 points
872 views
0 votes
1 answer

How to temporarily disable a foreign key constraint in MySQL?

Hello @kartik, To turn off foreign key constraint ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,840 points
2,437 views
0 votes
1 answer

How do I use Django templates without the rest of Django?

Hello @kartik, Let's say you have this important ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,840 points
1,555 views
0 votes
1 answer
0 votes
1 answer

How to secure APIs for Registration and Login in Django Rest Framework?

Hello @kartik, you cannot have an authentication system ...READ MORE

answered Jun 25, 2020 in Python by Niroj
• 82,840 points
2,871 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP