logoalt Hacker News

aidoslast Friday at 11:13 PM1 replyview on HN

I wasn’t totally clear on my original statement. As you point out, the referenced columns in the referenced table need to have a unique constraint and that’s done with a unique index. My understanding is that this ensures there’s no ambiguity as to which row is referenced and allows for efficient enforcement of the FK constraint.

Django automatically creates an index on the referencing table to ensure that joins are fast. The fact that you have the relationship in the ORM means that’s how you’re likely to access the data so it makes perfect sense.

The mental model mismatch I’ve seen is that people appear to think of the relationship as being on the parent object “pointing” at the child table.


Replies

bevr1337yesterday at 3:41 AM

I'll admit my experience in Django is only migrating customers off Django. Thanks for adding some interesting details about that ecosystem