mysql foreign key error #1452

后端 未结 4 1585
北荒
北荒 2020-12-18 05:38
ALTER TABLE  `groups` ADD FOREIGN KEY (  `company_id` ) REFERENCES  `summaries`.`companies` (

`id`
) ON DELETE CASCADE ;

MySQL said: 

#1452 - Cannot add or update         


        
4条回答
  •  一生所求
    2020-12-18 06:07

    That means you have at least one row in the child table that references a non-existent row in the parent table.

    If you are absolutely sure that you are okay with having a data integrity issue like that, you can add the foreign key by disabling foreign key checks before you run the ALTER TABLE command:

    SET FOREIGN_KEY_CHECKS = 0;
    

提交回复
热议问题