본문 바로가기

에러일지

2024-02-08 DB의 참조 무결성

cannot add or update a child row: a foreign key constraint fails (`bbs`.`board`, constraint `board_ibfk_1` foreign key (`uid`) references `users` (`uid`) on delete restrict on update restrict)

cannot add or update a child row: a foreign key constraint fails 
(`bbs`.`board`, constraint `board_ibfk_1` foreign key (`uid`) references `users` (`uid`) on delete restrict on update restrict)

 

 

참조 무결성: 참조 무결성은 관계 데이터베이스 관계 모델에서 2개의 관련 있던 관계 변수 간의 일관성을 말한다. (위키백과)

 

상황:  DB에 user table과 board table(foreign key로 user table의 uid를 가짐) 이 존재

에러:  user table에 brain이라는 user가 있지만 board table에선 brian으로 등록. 즉 브라이언을 브래인으로 잘못씀 

 

에러난 이유: board table은 user table과 연결되어있기에 user table에 없는 것을 board table에 등록할려고 하니 에러가 남 즉 참조 무결성 위반

 

해결: brain -> brian

// b = new Board("제목 6", "본문 6", "brian"); 
브라이언을 브래인으로 잘못씀 

 


🔗레퍼런스

  • 위키백과. 참조 무결성