MySQL Creating tables with Foreign Keys giving errno: 150

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

    (Side notes too big for a Comment)

    There is no need for an AUTO_INCREMENT id in a mapping table; get rid of it.

    Change the PRIMARY KEY to (role_id, role_group_id) (in either order). This will make accesses faster.

    Since you probably want to map both directions, also add an INDEX with those two columns in the opposite order. (There is no need to make it UNIQUE.)

    More tips: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#speeding_up_wp_postmeta

提交回复
热议问题