티스토리 뷰

어제의 디버깅은 끝나지 않았다.

django.db.utils.IntegrityError: Problem installing fixtures: The row in table 'taxi_profile' with primary key '9' has an invalid foreign key: taxi_profile.user_id contains a value '30' that does not have a corresponding value in auth_user.id.

그리고 내일도 계속 될 예정이다.


어제 끝날 때 즈음 https://stackoverflow.com/questions/35257550/migrating-to-mysql-in-django을 발견했다.


나랑 똑같은 에러다.

답변을 보니까 그 데이터를 지우라는데.... 뭐 그걸 어떻게 지워? 데이터가 날아가면 그게 무슨 소용이냐 싶었다. 그래서 무시했다.

조력자의 도움을 받는데, 바쁜지 나중엔 답을 못해주심 ㅠㅠ

그러다 다시 처음부터 다시 다 따라해보는데, 그러다 찾은 https://github.com/Atomidata/django-audit-log/issues/32

여기도 데이터를 지웠다더라... 하... 데이터를 지워야 하나 싶어서 sqlite3 명령어를 익혔다. mysql랑 또 조금 다르더라.

그리고 문제가 된 데이터 하나 값을 지워보니, 그 다음 데이터도 문제가 되었다.

정확히 문제는 profile 확장한 것에서 문제가 생긴 것이다. 장고의 기본 user model에서 추가 정보를 저장하기 위해 새로운 모델을 만들고 기본 user model과 연결했는데, 연결고리가 이상한 것이다.

(참고 : https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html#onetoone
위의 사이트를 따라 profile을 확장했었다.)


그래서 이번엔 문제가 된 데이터필드를 아예 날려버렸다. sqlite3에서는 mysql처럼 쉽게 column하나를 날리지 못하더라.

https://stackoverflow.com/questions/8442147/how-to-delete-or-add-column-in-sqlite
https://stackoverflow.com/questions/5938048/delete-column-from-sqlite-table/5987838#5987838

위의 것을 참고해서 column 하나를 날려서 해봤는데....

에러가 또 났다. 에러 대잔치~

django.core.serializers.base.DeserializationError: Problem installing fixture '/home/heesu/proj/mysite/iinitial_data.json': Expecting ',' delimiter: line 395 column 2 (char 12396)

이건 또 무슨 에러냐... 검색해보니 더 복잡해졌다.
응~ 이건 아닐거야~ 하고 다시 되돌아갔다.

자, 이번엔 새로운 시도로, 문제가 된 table을 빼고 dumpdata를 해보자!

python manage.py dumpdata taxi.recruit --natural-primary --exclude=contenttypes --exclude=auth.Permission --exclude=admin.logentry --exclude=sessions.session --indent 4 > initial_data.json

taxi.recruit만 저장해봤다.
dumpdata 사용법 : https://coderwall.com/p/mvsoyg/django-dumpdata-and-loaddata

아니 근데 되잖아??? mysql에서 loaddata가 됐다! 제대로 mysql에 들어갔다.

머리가 막 돌아갔다. 작전변경! taxi.profile은 어차피 직접 하나하나 등록해서 옮기면 되는 데이터들이다.(비밀번호처럼 암호화된 것은 auth.user에 있다.) taxi.profile을 빼고 나머지만 옮기자!

음... 근데 내일 해봐야지... 왜냐면 이미 늦었고, 은근히 옮겨야할 table이 많더라. django log파일도 있고, auth group에 각종 permission db도 있다.

지금 상태로는, auth_user와 recruit은 잘 옮겼다.
auth_user의 profile은 다 default 값이더라. 혹시 이게 충돌이 나서 그런가? 왜 그럴까

댓글