amoxu

amoxu学习记录以及分享

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
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mistyrain0109/article/details/79972494
个人分类: MySQL 存储过程
上一篇Spring Mybatis 在service层不关闭sqlsession连接池一次获取分页查询的总数量和数据
下一篇Java 使用protostuff实现快速的对象深拷贝
想对作者说点什么? 我来说一句

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

关闭
关闭