phpmyadmin 中的多个外键

Multiple foreign keys in phpmyadmin

我正在尝试在 table 中添加 2 个外键,但是当我创建第二个外键时,它会出现如下错误:

1452 - Cannot add or update a child row: a foreign key constraint fails (foodsuggestion.#sql-b54_1b, CONSTRAINT #sql-b54_1b_ibfk_1 FOREIGN KEY (Res_id) REFERENCES restaurant (Res_id))

确保 child table 中没有包含不在主 table 即餐厅中的 Res_id 数据的行。此外,如果您在问题中包含 table 的结构,将会更容易理解。

例如:

主人table餐厅

res_id|other column|
------|------------|--
  1   |            |
  2   |            |

child table

id|res_id|other column|
--|------|------------|---
1 |  1   |            |
2 |  2   |            |
3 |  3   |            |

这将不起作用并给出外键约束失败错误。