코딍코딍
코딩기록
코딍코딍
전체 방문자
오늘
어제
  • 분류 전체보기 (271)
    • 개발 (2)
    • Java (1)
    • 스프링 (28)
    • JPA (11)
    • Git (3)
    • 알고리즘 (160)
      • 백준 (132)
      • 프로그래머스 (8)
      • SWEA (20)
    • 토이 프로젝트 (14)
      • 간단한 Springboot CRUD (1)
      • 게시판 프로젝트 (13)
    • 알고리즘 개념정리 (8)
    • 오류 해결 (13)
    • 보류 (0)
    • AWS (5)
    • 트러블 슈팅 (0)
    • 회고 (3)
    • CS (4)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

최근 글

티스토리

hELLO · Designed By 정상우.
코딍코딍
오류 해결

[Mysql] Cannot delete or update a parent row

오류 해결

[Mysql] Cannot delete or update a parent row

2023. 2. 28. 15:28

 

https://haenny.tistory.com/78

 

[Error] MySQL 에러 Cannot delete or update a parent row: a foreign key constraint fails

[Error] MySQL 에러 Cannot delete or update a parent row: a foreign key constraint fails 에러 로그 ### Cause: java.sql.SQLIntegrityConstraintViolationException: (conn=4502) Cannot delete or update a parent row: a foreign key constraint fails (`taat_vo

haenny.tistory.com

 

 

//게시물 삭제
    @DeleteMapping("/{boardId}")
    public ResponseEntity deleteBoard(@PathVariable Long boardId) {
        //board, home, homeImage 삭제
        Board board = boardService.findOne(boardId);
        Home home = homeService.findOne(board.getHome().getId());
        List<HomeImage> homeImages = home.getHomeImages();

        boardService.delete(board);
        homeService.delete(home);
        homeImages.forEach(homeImageService::delete); //여기서 문제 => 프록시 초기화 객체로 삭제 가능?
        //Cannot delete or update a parent row
        //Board => HomeImage => Home 순으로 삭제 => 티스토리 업로드

        return ResponseEntity.ok("");
    }

 

해결

//게시물 삭제
    @DeleteMapping("/{boardId}")
    public ResponseEntity deleteBoard(@PathVariable Long boardId) {
        //board, home, homeImage 삭제
        Board board = boardService.findOne(boardId);
        Home home = homeService.findOne(board.getHome().getId());
        List<HomeImage> homeImages = home.getHomeImages();

        boardService.delete(board);
        homeImages.forEach(homeImageService::delete); //여기서 문제 => 프록시 초기화 객체로 삭제 가능?
        homeService.delete(home);
        //Cannot delete or update a parent row
        //Board => HomeImage => Home 순으로 삭제 => 티스토리 업로드

        return ResponseEntity.ok("");
    }

 

 

'오류 해결' 카테고리의 다른 글

[Spring Data JPA] No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call 오류 해결  (0) 2023.04.19
[JPA] More than one row with the given identifier was found: 1  (0) 2023.03.11
Java Mysql 연동 시 오류 발생 : java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed  (0) 2023.02.13
java.lang.StackOverflowError: null - @Data  (0) 2023.01.11
failed to lazily initialize a collection of role: could not initialize proxy - no Session  (0) 2023.01.11
    '오류 해결' 카테고리의 다른 글
    • [Spring Data JPA] No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call 오류 해결
    • [JPA] More than one row with the given identifier was found: 1
    • Java Mysql 연동 시 오류 발생 : java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
    • java.lang.StackOverflowError: null - @Data
    코딍코딍
    코딍코딍
    ㅎ2

    티스토리툴바

    단축키

    내 블로그

    내 블로그 - 관리자 홈 전환
    Q
    Q
    새 글 쓰기
    W
    W

    블로그 게시글

    글 수정 (권한 있는 경우)
    E
    E
    댓글 영역으로 이동
    C
    C

    모든 영역

    이 페이지의 URL 복사
    S
    S
    맨 위로 이동
    T
    T
    티스토리 홈 이동
    H
    H
    단축키 안내
    Shift + /
    ⇧ + /

    * 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.