MySQL 5.5 errno: 150 “Foreign key constraint is incorrectly formed”

前端 未结 3 1628
独厮守ぢ
独厮守ぢ 2021-01-16 20:25

There are plenty of questions regarding this error but I can\'t seem to find any similar scenario to what I have.

My 1st table (users):

My 2nd table

3条回答
  •  天命终不由人
    2021-01-16 20:45

    • Verify that the datatypes match (except for PRIMARY KEY).
    • Verify that both tables are ENGINE=InnoDB.

    Even after that, error 150 can still occur. 3 ways around it:

    • Disable FKs while creating the tables, then re-enable.
    • CREATE TABLEs without FKs, then ALTER ... ADD ... FKs
    • Be sure the do the CREATEs in just the right order.

    A side note: In INT(2), the (2) is irrelevant. All INTs are 4 bytes.

提交回复
热议问题