에러 모음

[Django] Table '프로젝트명.socialaccount_socialapp_sites' doesn't exist

개발자 지망생 리네 2025. 6. 3. 14:55

- SocialApplication과 Site 사이의 다대다 관계를 저장하는 테이블이 DB에 생성되지 않음

-> migrate를 하려고 하였으나 해당 테이블이 이미 존재한다는 에러 메시지를 전달받음

 

 

원인

- mysql DB에 일부 테이블은 생성되어 있고, 일부 테이블이 누락된 상태

- Django가 '그거 아마 없을 걸? 아니네? 있나? 아닌데, 없는... 있나?' 라며 혼란스러운 상황

-> 완전히 초기화하자!

 

 

해결 방법

(1) 테이블이 실제로 온전히 존재하는 지 확인

- mysql에 접속해서 아래 코드를 입력

mysql -u 사용자이름 -p
# 비밀번호 입력
USE schello;
SHOW TABLES LIKE '%socialaccount%';

 

테이블 목록에 아래 네 개는 꼭 나와야 정상임.

socialaccount_socialapp
socialaccount_socialaccount
socialaccount_socialtoken
socialaccount_socialapp_sites

 

만일 socialaccount_socialapp_sites가 존재하지 않는다면 해당 테이블이 누락되어 있는 상태. 아래 방법대로 실행.

 

(2) __pycache__ + 마이그레이션 파일 삭제

find . -path "*/migrations/*.pyc" -delete
find . -path "*/migrations/__pycache__" -delete

 

(3) 마이그레이션 강제 초기화

-> socialaccount는 마이그레이션 안 했다고 속임

python manage.py migrate --fake socialaccount zero

 

(4) MySQL에서 테이블 전부 지우기

- mysql 접속 후 아래 코드 입력

DROP TABLE IF EXISTS socialaccount_socialaccount;
DROP TABLE IF EXISTS socialaccount_socialapp;
DROP TABLE IF EXISTS socialaccount_socialtoken;
DROP TABLE IF EXISTS socialaccount_socialapp_sites;

 

(5) 마이그레이션

python manage.py migrate socialaccount