skip to Main Content

The problem is that when using order_by(), Ukrainian letters are incorrectly sorted alphabetically, that is, before "а", "б" is placed "і" and "є".

2

Answers


  1. Chosen as BEST ANSWER

    Changing the column encoding to utf8mb4_unicode_ci helped me. PS. Failed to change the encoding of the entire database or table. Only the column.

    But later it turned out that this was not enough for me. I need to sort addresses that contain letters and numbers. In the end I was able to do it the way I needed with Natsort

    from natsort import humansorted
    import locale
    
    locale.setlocale(locale.LC_ALL, 'uk_UA.UTF-8')
    objects = humansorted(objec, key=lambda p: p.address)
    

  2. You can change the collation of all columns of a table this way:

    ALTER TABLE <mytable> CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    

    There’s no statement to change all tables in one operation. You have to do it one table at a time.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search