MySQL Creating tables with Foreign Keys giving errno: 150

前端 未结 20 2410
深忆病人
深忆病人 2020-11-21 05:02

I am trying to create a table in MySQL with two foreign keys, which reference the primary keys in 2 other tables, but I am getting an errno: 150 error and it will not create

20条回答
  •  悲哀的现实
    2020-11-21 05:36

    Helpful tip, use SHOW WARNINGS; after trying your CREATE query and you will receive the error as well as the more detailed warning:

        ---------------------------------------------------------------------------------------------------------+
    | Level   | Code | Message                                                                                                                                                                                                                                 |
    +---------+------+--------------------------------------------------------------------------                          --------------------------------------------------------------------------------------------                          ---------------+
    | Warning |  150 | Create table 'fakeDatabase/exampleTable' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.
    |
    | Error   | 1005 | Can't create table 'exampleTable' (errno:150)                                                                                                                                                                           |
    +---------+------+--------------------------------------------------------------------------                          --------------------------------------------------------------------------------------------                          ---------------+
    

    So in this case, time to re-create my table!

提交回复
热议问题