by twelve40 · 3y ago · 0 comments
https://docs.djangoproject.com/en/4.1/topics/db/examples/one...
yes, orms have a ton of problems, but it's clearly very much a thing.
I don't think it's very elegant and people often forget the unique constraint.
One table is a much better solution.
How does this guarantee that the ID is in both tables?
At the database level there's only one kind of foreign key.
Yeah, you can try and prevent it from happening in code or throw some unique constraints at it, but it's unnecessary.
Yes, you can hack it with a unique constraint, but it's not very elegant.
I'd rather follow the rules of normalisation wherever possible.
Yes, you can try and artificially limit them to 1:1 using constraints but it's a hack.
The correct way to represent a 1:1 relationship in a database is with one table.