외래 키를 설정하려면 Collation 값이 일치해야 한다.

 

Collation 값 확인하는 방법

show full columns from article ;

 

아래와 같은 방법으로 Collation 값을 변경한다.

alter table category convert to character set utf8 collate utf8mb3_general_ci;

 

 

SQL Error [1452] [23000]: (conn=3205) Cannot add or update a child row: a foreign key constraint fails 

 

Collation 값을 일치시켜준 후 외래 키를 생성하려고 하니 위와같은 오류를 만나게 되었다.

위 오류는 외래키를 생성하려는 테이블에서 외래키를 만들려는 값에 참조 테이블에 없는 값을 가지고 있기 때문이다.

 

+ Recent posts