This is a common foreign key problem that MySQL and friends usually do not support. There are two ways to do this.
First, how you did it are nullable foreign keys, one for each type.
The other, as in Django Content Types , must have a connection table, each row has a row identifier and a field that indicates the table to search. Then your code should formulate an SQL query depending on the contents of the field. It works well, but has limitations:
The downside of the first is bloat, but it brings you problems with normal FKs, i.e. referential integrity and SQL joins, etc., which are very valuable. You cannot get them with the second method.
source share