Two foreign keys in one column from one table

I have a project table that has an image_id field and a newsimage_id field.

Both are associated with an image table. But InnoDB does not allow me to set the foreign key for both fields in the same column ( id ).

Is there a way I can do this, or is this not possible? I am using MySQL through MAMP.

Thanks in advance!

+4
source share
1 answer

This is how I did it (MySQL 5.0.45):

 ALTER TABLE `job_dependency` ADD FOREIGN KEY (`job`) REFERENCES `job` (`id`), ADD FOREIGN KEY (`dependency`) REFERENCES `job` (`id`); 

In this situation, there are problems with ON DELETE CASCADE, so do not use it.

+5
source

Source: https://habr.com/ru/post/1306927/


All Articles