Django + PostgreSQL sorting with ÆØÅ
I ran into an issue where Django sorted Ø as O, and it turns out that my Postgres database was set up with the wrong collation. Here's how to fix it.
This was posted on my previous blog on Tumblr a long time ago, but I figured I wouldn't let it disappear into the internet void, so I'm republishing it here.
How to fix it
Dump your existing database:
pg_dump your_db > your_db.sql
Rename your existing database (or delete it): psql
and then
ALTER DATABASE your_db RENAME TO your_db_backup;
Create a new database:
createdb your_db –lc-collate=nb_NO.UTF-8 –lc-ctype=nb_NO.UTF-8 -T template0
Reimport your dump: psql your_db < your_db.sql
And you're done!