Categories
Django

Fix: ValueError: unknown locale: UTF-8

I was setting up the python.org website code, built on Django, on my local machine I encountered the error ValueError: unknown locale: UTF-8 while running the ./manage.py migrate command. See screenshot below:

Screenshot 2020-05-06 at 01.06.57

To fix this, I had to set the following environment variables:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

There, back to code.

Categories
Django

Migrating multiple CharFields to null=False

I am working on a simple project built on top of Django web framework. I have a user profile model that had 3 char fields that needed to be update from null=True to null=False

When I run python manage.py migrate on the django app I get the following error django.db.utils.OperationalError: cannot ALTER TABLE "accounts_profile" because it has pending trigger events To fix this I run the PostgreSQL shell (psql) to update and set the changed fields.

The SQL command for the fix is:
db=# update accounts_profile set non_nullable_field = '' where non_nullable_field is null;

I run the same command for the other two different fields.

Follow me on twitter @bmwasaru