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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mistyrain0109/article/details/79972494

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
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页