MySQL “ERROR 1005 (HY000): Can't create table 'foo.#sql-12c_4' (errno: 150)”

后端 未结 14 784
情深已故
情深已故 2020-12-03 04:13

I was working on creating some tables in database foo, but every time I end up with errno 150 regarding the foreign key. Firstly, here\'s my code for creating t

相关标签:
14条回答
  • 2020-12-03 05:08

    Check that BOTH tables have the same ENGINE. For example if you have:

    CREATE Table FOO ();
    

    and:

    CREATE Table BAR () ENGINE=INNODB;
    

    If you try to create a constraint from table BAR to table FOO, it will not work on certain MySQL versions.

    Fix the issue by following:

    CREATE Table FOO () ENGINE=INNODB;
    
    0 讨论(0)
  • 2020-12-03 05:08

    Solved:

    Check to make sure Primary_Key and Foreign_Key are exact match with data types. If one is signed another one unsigned, it will be failed. Good practice is to make sure both are unsigned int.

    0 讨论(0)
提交回复
热议问题