1553: Cannot drop index needed in a foreign key constraint (외래 키 제약 조건에 필요한 인덱스 삭제 불가)
MySQL의미
외래 키 제약 조건에 필요한 인덱스를 삭제하려 한다. InnoDB는 FK가 의존하는 인덱스를 제거하도록 허용하지 않는다.
원인
InnoDB에서는 모든 외래 키가 참조하는 컬럼에 인덱스를 필요로 한다. DROP INDEX로 그 인덱스를 삭제하면 FK 제약 조건이 지원을 잃게 되므로 거부된다. 보통 테이블 재구성(인덱스 정리) 중에 발생한다.
해결 방법
먼저 외래 키 제약 조건을 삭제한 후 인덱스를 삭제한다: ALTER TABLE my_table DROP FOREIGN KEY fk_name; 이후 DROP INDEX idx_name ON my_table; 필요하면 다른 적절한 인덱스에 의존하도록 FK를 다시 생성한다. 기존 FK 목록: SELECT constraint_name, table_name FROM information_schema.key_column_usage WHERE referenced_table_name IS NOT NULL;
같은 데이터베이스의 다른 항목
- 1129Host 'host' is blocked because of many connection errors (연결 오류가 많아 호스트 차단됨)
- 1194Table 'name' is marked as crashed and should be repaired (테이블이 crashed로 표시되어 복구 필요)
- 1615Prepared statement needs to be re-prepared (prepared statement 재준비 필요)
- 3948Loading local data is disabled; this must be enabled on both the client and server sides (로컬 데이터 로드가 비활성화됨. 클라이언트와 서버 양쪽에서 활성화 필요)
- 1075Incorrect table definition; there can be only one auto column and it must be defined as a key (잘못된 테이블 정의. auto 컬럼은 하나만 가능하며 키로 정의해야 함)
- 1055Expression not in GROUP BY (only_full_group_by) (GROUP BY에 없는 표현식)
- 1267Illegal mix of collations