2 years ago
#60763

user12314098
Heroku & Django - Change client encoding from WIN1252 to UTF8
So I have my Django application deployed on a Heroku server and when I try to query for Post
I get this.
How I query
// Command to get into postgres
heroku pg:psql
// Query
SELECT * FROM posts;
What I get back
ERROR: character with byte sequence 0xf0 0x9f 0x98 0x84 in encoding "UTF8" has no equivalent in encoding "WIN1252"
I'm decently sure what is happening is that someone created a post where the body
has an emoji in it. I'm using Postgresql it supports UTF8
for storing. So I'm not really sure why this is happening because Django should default to UTF8
, because it's running postgres and then I ran this command to check the server encoding.
>>>heroku pg:psql -c "show server_encoding"
--> Connecting to postgresql-round-92478
server_encoding
-----------------
UTF8
(1 row)
So I'm not sure which part of the client server is in WIN1252
and needs to be converted to UTF8
.
How do I change client encoding from WIN1252
to UTF8
?
models.py
class Post(models.Model):
uuid = models.UUIDField(primary_key=True, editable=False)
created = models.DateTimeField('Created at', auto_now_add=True)
updated_at = models.DateTimeField('Last updated at', auto_now=True, blank=True, null=True)
creator = models.ForeignKey(
User, on_delete=models.CASCADE, related_name="post_creator")
body = models.CharField(max_length=POST_MAX_LEN, validators=[MinLengthValidator(POST_MIN_LEN)])
Setup:
- Postgresql
- Django 3.2.9
- Deployed on Heroku
python
django
postgresql
heroku
heroku-postgres
0 Answers
Your Answer