首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException

作者头像
呱
发布于 2020-10-23 10:49:34
发布于 2020-10-23 10:49:34
2.2K0
举报
文章被收录于专栏:后端JavaEE后端JavaEE

1.错误截图

自己在idea中写一个测试类,也不能删除pid为1的那条数据,报错如下

代码语言:javascript
复制
package test;

import entity.Product;
import mapper.ProductMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * zt
 * 2020/10/12
 * 21:38
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:application.xml")
public class TestMapper {
    @Autowired
    private ProductMapper mapper;
    @Test
    public void test1(){
        Product p = new Product();
        p.setTid(1);
        p.setPname("aaa");
        mapper.add(p);
    }

    @Test
    public void test2(){

        mapper.delete(2);
    }

}

2.错误原因

所以删除最后那条自己刚刚添加的数据,因为这条数据没有和购物车表中数据有外键约束,所以删除并不会报错

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/10/13 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • 1.错误截图
  • 2.错误原因
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档