~/talk

How to get Foreign Keys horribly wrong in Django

Talkat DjangoCon Europe 2025 · 2025-04-23..04-27· [python, databases]
slides:none on file

Shows that Django’s foreign keys create implicit indexes that can bloat schemas and trigger expensive, blocking work: unique_together → use a unique constraint, db_index on FK is implicit so drop it only by using separate_database_and_state with reversible SQL, and create/drop indexes concurrently (atomic=False) to avoid locks. Demonstrates with 1,000,000 products and 100 users, dropping a 6MB index and replacing it with a partial index reduces 6MB to 32K, and explains using select_for_update(of="self") to avoid locking joined rows.

AI-written summary · about

  1. 0:00Introduction and Data Model
  2. 2:18Unique Constraints
  3. 4:09Managing Implicit FK Indexes
  4. 5:55Migrations and Locking
  5. 9:45Concurrent Operations
  6. 11:14Indexes on Foreign Keys
  7. 12:24Performance of Deletes
  8. 16:33Partial Indexes
  9. 22:02Advanced Migration Techniques
  10. 26:48Concurrency and Locking
  11. 31:45Optimizing Locks
  12. 33:36Q&A and Conclusion
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.