장바구니 아이템 테이블을 생성 중 만난 에러 errno: 121 "Duplicate key on write or update"

해당 스키마에 똑같은 이름의 제약 조건이 있다는 에러이다.
https://stackoverflow.com/questions/20512572/duplicate-key-on-write-or-update
Duplicate key on write or update?
Duplicate key on write or update First i will like to acknowledge the fact that, i have been to similar posts, but i couldn't find a way to solve this annoying issue which i face as of present.I am
stackoverflow.com
그래서 fk 제약조건 이름의 규칙을 정했다.
"fk_기준 테이블명_참조테이블명_참조키" 형식으로 이름을 변경할 것이다.
cartItems .user_id > users.id : fk_cartItems_users_id
likes.user_id > users.id : fk_likes_users_id
참조키 이름을 변경하고 apply하니까 다시 만난 에러 ㅎ
ERROR 1061: Duplicate key name ~~~

테이블에 제약조건 걸때마다 즉, foreign key를 만들때마다 그 컬럼에 index가 자동으로 추가되면서 제약조건의 이름도 추가되어 발생한 에러이다.
내가 설정하지 않았지만 database에서 자동으로 생성하고 있었던 것임
해결방법은 인덱스 이름을 변경하면 된다!
indexes 탭에 들어가서 이름 변경 후 apply하면 끝!

'TIL' 카테고리의 다른 글
| 비관적 업데이트(pessimistic)? 낙관적(optimistic) 업데이트? (0) | 2024.03.14 |
|---|---|
| AxiosError: Network Error / CORS 에러 (0) | 2024.02.29 |
| Error: listen EADDRINUSE: address already in use [PORT] (1) | 2023.12.29 |
| Error Cannot find module 'express' & your cache folder contains root-rowned files, due to a bug ~ (0) | 2023.12.14 |
| TIL 8일차 - 백엔드 구조, 웹 서버 역할, Node.js 설치 (1) | 2023.11.30 |