在表中使用一组外键的技术的名称是什么,其中除了一个外键对于给定行都是 NULL?
换句话说,每一行都需要一个外键指向 n 个不同的可能表中的一个(并且只有一个),因此您实际上拥有所有必要的外键,但除了一个外键都是 NULL。
(Django 的用户可能认为这是使用通用外键的替代方法)
最佳答案
您描述的设计术语是Exclusive Arc。
相反,我更喜欢制作一个外键来引用您的 n 个不同父表的公共(public) super 表。
请参阅我对多态关联的其他回答:
- Possible to do a MySQL foreign key to one of two possible tables?
- Referencing foreign keys in the same column
- Why can you not have a foreign key in a polymorphic association?
- In a StackOverflow clone, what relationship should a Comments table have to Questions and Answers?
- How to handle an “OR” relationship in an ERD (table) design?
关于database - 一组外键,其中除了一个外都是 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2117601/