[mysql] MySQL Error 1215: Cannot add foreign key constraint

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.