0

I'm using PHP's PDO driver/API/library to create some tables in MySQL. When MySQL can't create a table due to a foreign key constraint problem, it returns the following error

Can't create table 'dbname.table_name' (errno: 150)

Is there anyway to have MySQL tell you (or to automatically lookup/analyze) why it couldn't create the table. For example, if you attempt to create a table with 10 foreign keys, and one key is invalid, is there a way to have MySQL tell you which one is the problematic key? Or do you need to rely on human intelligence and debugging to figure this out for yourself?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • 3
    `show engine status innodb` will have a "last foreign key error" section that tells you why an FK operation failed. – Marc B Jun 18 '14 at 14:26
  • http://stackoverflow.com/questions/4061293/mysql-cant-create-table-errno-150 Check this post – Cornel Raiu Jun 18 '14 at 14:28

1 Answers1

0

The closest I've been able to come on this is using the perror command

It won't give fine grained details, but it will give you a plain english explanation of the error code.

$ perror 150
MySQL error code 150: Foreign key constraint is incorrectly formed

$ perror 151
MySQL error code 151: Cannot add a child row
Alana Storm
  • 164,128
  • 91
  • 395
  • 599