I have these two tables called "Timelines" and "Universes". In "Timelines" I have a column named "ID" which must be a combination of a Timeline's ID after the ID of its related Universe. For that reason I created a Stored Virtual Column to be the Primary key of "Timelines" table, called "ID".
This "ID" must be a combination of two other columns in the same table, "UniverseID" and "TimelineID", So the expression for Virtual Column ("ID") is :
CONCAT(UniverseID, ':', TimelineID)
But, UniverseID MUST refer to the column "ID" in the table "Universes". So I try to make it a Foreign key. But there's a problem. I can't. Here's what I try to do :
ALTER TABLE `Timelines` ADD CONSTRAINT `Timelines__UniverseID` FOREIGN KEY (`UniverseID`) REFERENCES `Universes`(`ID`) ON DELETE CASCADE ON UPDATE CASCADE;
And I get this error :
#1215 - Cannot add foreign key constraint
There is NO OTHER FOREIGN KEY with that name in any other table !
What should I do ? Is there a problem with my Design ? Or is there another way to get the same result ?