
Djangonaut diaries, week 4: Eliminating a Redundant Index in Django's ORM
Hello again! Last week, we discussed issue #22125 , to prevent a redundant database index from being created on Many-to-many "through" tables. We geeked out a lot about composite indexes, reproduced the issue, and now it's time to send a patch for it. One interesting thing about this ticket, is that there was in fact a PR created addressing it, 8 years ago! A few years later, it was closed due to inactivity. That PR had some aspects that make a lot of sense, most importantly, it sets db_index=False in the function create_many_to_many_intermediary_model , which seems to be the change we need to do. Let's understand what happens there. How are many-to-many models defined in Django? As I've explained in the previous article, a many-to-many (m2m) relationship normally needs an intermediary table to store these links. For example if I have model Book and a model Author , and I want my app to allow a book to have several authors and an author to have several books, I will need a through-tabl
Continue reading on Dev.to
Opens in a new tab




