Mysql 存储过程批量插入数据出错:Cannot add or update a child row: a foreign key constraint fails

Procedure execution failed
1452 - Cannot add or update a child row: a foreign key constraint fails (buzz.friends, CONSTRAINT friend_duid FOREIGN KEY (duid) REFERENCES user (uid) ON DELETE CASCADE ON UPDATE CASCADE)

BEGIN
    #Routine body goes here...

DECLARE i INT;

set i = 33;
 WHILE i<635 Do
#INSERT INTO test(test.`name`,test.a) VALUES("武汉","hahhahahah");
INSERT INTO buzz.friends (`suid`, `duid`) VALUES(1,i);
set i := 1+i;
END WHILE;
END


//注意是set i=1+i;不是 set i=i+1; 
//set i=i+1就会报错Cannot add or update a child row: a foreign key constraint fails

你可能感兴趣的:(MySQL,存储过程)