MySQL Cannot Add Foreign Key Constraint

后端 未结 22 1813
时光取名叫无心
时光取名叫无心 2020-11-22 08:35

So I\'m trying to add Foreign Key constraints to my database as a project requirement and it worked the first time or two on different tables, but I have two tables on which

22条回答
  •  粉色の甜心
    2020-11-22 08:49

    To set a FOREIGN KEY in Table B you must set a KEY in the table A.

    In table A: INDEX id (id)

    And then in the table B,

    CONSTRAINT `FK_id` FOREIGN KEY (`id`) REFERENCES `table-A` (`id`)
    

提交回复
热议问题