티스토리 뷰
django에서 이미 존재하던 db.splite3 (sqlite database)의 정보를 mysql로 옮길 것이다.
converter도 있고 코딩으로 바꾸는 것도 있지만, django의 db backup 기능으로 손쉽게 사용하는 방법이 있는 것 같다.
즉, django의 setting.py에서 sqlite3가 db로 설정된 상태에서
python manage.py dumpdata > datadump.json
바꾸고 난 후, 바로 직전 포스트에 올렸듯이, setting.py에서 mysql을 사용할 때의 설정을 바꾼다.
그리고 다음과 같은 명령어를 치면!
python manage.py loaddata datadump.json
다음과 같은 에러가 난다. utf-8 (인코딩) 관련 에러 같다.
_mysql_exceptions.OperationalError: (1366, "Incorrect string value: '\\xEC\\x9D\\xB4\\xED\\x85\\x8C...' for column 'host_name' at row 1")
아하! mysql은 기본적으로 한글세팅이 안되어 있으면 비슷한 에러가 나는구나.
하라는 대로 설정 바꾸고, 기존의 mysql database를 지우라고해서 지웠다. (저번 글에서 tutorial 따라가다보면 step 4에서 CREATE DATABASE를 한 부분이 있다.)
명령어는 DROP DATABASE (이름)
그러고 나서 다시 CREATE DATABASE하니 제대로 UTF-8을 받더라.
그 후에 loaddata를 다시하니 문제 하나 해결! 아까와 같은 에러는 안 생겼다. utf-8문제는 풀렸다.
대신 다른 에러가 생겼지롱~ 하핳ㅎ하핳하 역시 코딩은 디버깅이다.
django.db.utils.ProgrammingError: Problem installing fixture '/home/(name)/proj/mysite/output.xml': Could not load taxi.Recruit(pk=27): (1146, "Table 'taxi_data.taxi_recruit' doesn't exist")
찾아보니 1146 에러는 다른 사람들도 많이들 고민했던 문제 같다.
python manage.py migrate를 했냐고 묻는 질문에 좋아요가 많더라. 그러면 해결되나? 아니, 난 안 됨 ㅎ
(https://stackoverflow.com/questions/27583744/django-table-doesnt-exist)
아! mysql 리셋을 안 했네 ㅋㅋㅋㅋ (python manage.py sqlflush (db가 다 날아간다) / sudo systemctl restart mysql)
리셋하고 다시 python manage.py migrate 하니까 됨.
새로운 에러다. 이건 아까 어디선가 이런 에러가 난다고 본 기억이 있다.
django.db.utils.IntegrityError: Problem installing fixture '/home/(name)/proj/mysite/datadump.json': Could not load contenttypes.ContentType(pk=20): (1062, "Duplicate entry 'taxi-recruit' for key 'django_content_type_app_label_model_76bd3d3b_uniq'")
와... 이건 정말 옛날 것 밖에 없어서 하라는 대로 했는데 하나도 안 됐다. 그냥 이 방법을 포기하고 싶다. 다른 converter를 써볼까....
하는 와중에 색다른 에러가 나는 dumpdata 방법 발견!
(https://stackoverflow.com/questions/853796/problems-with-contenttypes-when-loading-a-fixture-in-django)
python manage.py dumpdata --natural-primary --exclude=contenttypes --exclude=auth.Permission --exclude=admin.logentry --exclude=sessions.session --indent 4 > initial_data.json
'gistalk 개발' 카테고리의 다른 글
django notification 사용하기 (1) (0) | 2018.01.22 |
---|---|
mysql 자동 백업하기 (0) | 2018.01.18 |
sqlite 데이터를 mysql 데이터로 변환하기 (3) (0) | 2018.01.18 |
sqlite 데이터를 mysql 데이터로 변환하기 (2) (0) | 2018.01.17 |
django에 myspl(database) 적용하기 (1) | 2018.01.15 |
- Total
- Today
- Yesterday
- django3
- 협업필터링
- python3.8
- Supervised Learning #KoNLPy #Keras #NLP #자연어처리 #글 분류 #LSTM
- 추천
- 서버환경
- 아이템기반
- memory-based
- MachineLearning #KMenas #KoNLPy #Word2Vec #AI #ML #인공지능 #Unsupervised #Clustering #Classification
- matrix market
- django mysql database sqlite
- MBCF
- IBCF
- gensim
- pythonpython
- javascrip
- WSL2
- buffalo
- queryset
- Python
- 메모리기반
- Collaborative Filtering
- django
- matrix factorization
- n core setting
- pytorch
- ifkakao
- item-based
- windows subsystem for lunux
- KAKAO
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |