andrepz
andrepz

Reputation: 481

Will Django always consider an Emoji as 1 character long?

I'm making a Post Reaction model that uses emojis as reactions, and at this point I'm not mapping them to Choices, but instead inserting the utf-8 value (e.g. 😀) directly to the Database (Postgres) as a CharField instance. This made me think which value should I use to the max_length of this field. I know Rust will take emojis as 1 char long, but I'm not sure about how python or Postgres will react.

Upvotes: 1

Views: 496

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246403

The length limit of a character varying column in PostgreSQL is always measured in characters, not in bytes. So emojis will count to the length limit either as 1 (if they are a single character) or as more (if they include a zero width joiner).

Upvotes: 3

Related Questions