~/talk

How to get Foreign Keys Horribly Wrong in Django

Talkat PyCon Israel 2025 · on Tuesday, 2025-09-09· [django, databases]
slides:none on file

Django silently creates indexes for ForeignKey fields and migrations often respond by dropping and recreating constraints (which forces a full check of parent rows), so inspect the SQL output, make migrations reversible by providing reverse SQL, and use SeparateDatabaseAndState to run only a drop index concurrently on the DB while changing state. For heavy traffic split changes into a non-transactional migration (atomic = False) or run an explicit add_index_concurrently and prefer partial index for sparsely populated audit columns (example: 1,000,000 products, partial index shrinks from 7 MB to 32 KB).

AI-written summary · about

  1. 0:00Introduction to foreign keys
  2. 3:40Unwanted index creation
  3. 8:45How Django migrations work
  4. 13:42Reversible migrations
  5. 17:41Concurrent index operations
  6. 21:39Foreign keys in deletions
  7. 23:28Partial indexes for performance
  8. 25:15Fixing index migrations
  9. 27:54Summary and takeaways
~/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.