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,510 points
2,436 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,880 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
474 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
583 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,880 points
2,147 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,880 points
682 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,880 points
2,081 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,880 points
1,228 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,880 points
2,658 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