MySQL Creating tables with Foreign Keys giving errno: 150

前端 未结 20 2421
深忆病人
深忆病人 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:17

    execute below line before creating table : SET FOREIGN_KEY_CHECKS = 0;

    FOREIGN_KEY_CHECKS option specifies whether or not to check foreign key constraints for InnoDB tables.

    -- Specify to check foreign key constraints (this is the default)

    SET FOREIGN_KEY_CHECKS = 1;
    

     

    -- Do not check foreign key constraints

    SET FOREIGN_KEY_CHECKS = 0;

    When to Use : Temporarily disabling referential constraints (set FOREIGN_KEY_CHECKS to 0) is useful when you need to re-create the tables and load data in any parent-child order

提交回复
热议问题