본문 바로가기

카테고리 없음

Request processing failed; nested exception is java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`springtest`.`attendance`, CONSTRAINT `fk_info_atten` FOREIGN KEY (`userid`) REFERENCES `..

마주친 오류)

Request processing failed; nested exception is java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`springtest`.`attendance`, CONSTRAINT `fk_info_atten` FOREIGN KEY (`userid`) REFERENCES `userinfo` (`userid`))

 

 

해결방법)

- sql무작정 복붙하지말고 테이블 어떻게 되어있는지 보기

- 챗지피티한테 물어보고 힌트를 얻었다.

 내가 테스트한다고 아이디에 아무거나 쳤던것이 문제였다.

 id가 외래키로 되어있어서 userinfo에 있는 id를 입력했어야 했다.

- 해결방법은 테스트를 할 때 attendence테이블의 userid를 입력할때 userinfo에 있는 userid들 중 하나로 썼어야 했다.

예를들어 userinfo에 아이디가 hello 비밀번호가 bye인 계정이 있다면

attendence 테이블에 아이디를 입력할때 hello를 입력해줘야한다.