5

i have a project table which has a image_id field and a newsimage_id field.

Both are linked to the image table. But InnoDB doesn't allow me to set a foreign key for both fields to the same column (id).

Is there a way I can do this or is it not possible? I'm using MySQL through MAMP.

Thanks in advance!!

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
makeflo
  • 53
  • 1
  • 3

1 Answers1

6

Here's 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`);

There are problems with ON DELETE CASCADE in this situation, so don't use it.

pzr
  • 1,226
  • 9
  • 6