MySQL Error 1215: Cannot add foreign key constraint

前端 未结 30 2755
予麋鹿
予麋鹿 2020-11-22 01:37

I am trying to forward engineer my new schema onto my db server, but I can\'t figure out why I am getting this error. I\'ve tried to search for the answer here, but everyth

30条回答
  •  孤街浪徒
    2020-11-22 02:03

    This is a subtle version of what has already been said, but in my instance, I had 2 databases (foo and bar). I created foo first and I didn't realize it referenced a foreign key in bar.baz (which wasn't created yet). When I tried to create bar.baz (without any foreign keys), I kept getting this error. After looking around for a while I found the foreign key in foo.

    So, long story short, If you get this error, you may have a pre-existing foreign key to the table being created.

提交回复
热议问题