Opened 4 years ago

Last modified 4 years ago

#31815 closed Bug

Can't Create PostgreSQL Database Constraints with non latin-1 encodings — at Initial Version

Reported by: JSAustin Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: encoding utf-8
Cc: Simon Charette Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am trying to create a model with a constraint on a field that uses UTF-8 encodings. Specifically, I'm trying to constrain scientific unit strings. The problematic one is: 'µg/mL'. The µ symbol has a b'\xc2\xb5' encoding with utf-8. When I add this as one of the check constraints, I get this error:

File "D:\DjangoSite\venv\lib\site-packages\django\db\backends\postgresql\schema.py", line 38, in quote_value

return psycopg2.extensions.adapt(value).getquoted().decode()

UnicodeEncodeError: 'latin-1' codec can't encode character '\u03bc' in position 0: ordinal not in range(256)

The migration is:
migrations.AddConstraint(

model_name='biomarkertestinfo',
constraint=models.CheckConstraint(check=models.Q(unitin=['μg/mL', 'ng/mL', 'pg/mL', 'U/L', 'mIU/mL', 'kIU/mL']), name='constrained biomarker unit choices'),

)

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top