Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails

前端 未结 21 2347
生来不讨喜
生来不讨喜 2020-11-22 01:32

I\'m having a bit of a strange problem. I\'m trying to add a foreign key to one table that references another, but it is failing for some reason. With my limited knowledge o

21条回答
  •  故里飘歌
    2020-11-22 02:17

    For me, this problem was a little different and super easy to check and solve.

    You must ensure BOTH of your tables are InnoDB. If one of the tables, namely the reference table is a MyISAM, the constraint will fail.

        SHOW TABLE STATUS WHERE Name =  't1';
    
        ALTER TABLE t1 ENGINE=InnoDB;
    

提交回复
热议问题