오류 발생
1. 테이블 삭제하려니까 외래키 때문에 안됨
2. 외래키를 삭제하려니까 아래와 같은 오류 발생
alter table [table_name] drop foreign key [key_name]
Error Code: 1091. Can't DROP 'key_name'; check that column/key exists
오류 내용
외래키를 삭제하려면 외래키 제약 조건 이름을 사용해야 하는데 해당 이름(key_name)의 제약 조건을 찾지 못했다는 오류
예를 들어
계약서 1조 3항을 지우고 싶은데 뜬금없이 '1조 지워주세요' 하는 격

오류해결
한 줄 요약 : FK 기호를 찾아서 제약 조건 이름을 입력해야 함
1. 아래 명령어를 입력하면 결과값이 아주 길게 출력되는데 그 값을 복사해서 메모장에 붙여넣기 (보기 쉽게)
2. ibfk 붙어있는 키 찾기
show create table table_name;
3. 아래 명령어를 입력해 제약 조건 이름 삭제 (1개일 수도 여러개 일수도 있음. 전부 삭제해야 함)
alter table table_name drop foreign key key_name_ibfk_1;
alter table table_name drop foreign key key_name_ibfk_2;
4. 테이블 삭제 (테이블 삭제는 항상 신중히 !!)
drop table table_name;
[참고] StackOverFlow
Can't Drop foreign key in MySQL
I have had a 1 to many relationship between course and instructor, which I wanted to drop. When I tried to drop the instructorID in course table it told me that. I couldn't drop it as it was a fore...
stackoverflow.com
'오류해결' 카테고리의 다른 글
| [Spring] 내 로컬에서는 잘 되던데..? (내로잘 체험기 feat.ddl-auto) (0) | 2023.05.06 |
|---|---|
| [MySQL] Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (0) | 2023.04.14 |
댓글