2021. 4. 21. 20:35ㆍDeveloper/Posting
뷰단 수정을 진행하였는데, 이로 인해 테스트케이스 통과가 안되는 이슈가 발생해서 도커가 자동으로 종료되는 일이 발생하였다.
이슈 해결을 위해 도커 로그를 보게 되었는데 아래와 같은 로그가 떠있어서 번역 및 구글링을 진행하여 해결하였다.
1. 이슈내용
2021-04-21T05:59:08.285801940Z ?: (mysql.W002) MariaDB Strict Mode is not set for database connection 'default'
- MariaDB Strict Mode가 '기본' 데이터베이스 커넥션으로 설정되어 있지 않습니다.
2021-04-21T05:59:08.285805079Z HINT: MariaDB's Strict Mode fixes many data integrity problems in MariaDB, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See:
힌트: MariaDB의 Strict Mode는 경고를 에러로 격상시켜 데이터 추가 시 데이터 잘림과 같은 데이터 베이스 내 데이터 무결성 문제를 해결합니다. 활성화하는 것이 좋습니다.
2. 해결하기
로그에서 보라는 문서는 아래와 같다.
docs.djangoproject.com/en/3.2/ref/databases/#mysql-sql-mode
Databases | Django documentation | Django
Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About ♥ Donate
docs.djangoproject.com
Setting sql_mode¶
From MySQL 5.7 onwards, the default value of the sql_mode option contains STRICT_TRANS_TABLES. That option escalates warnings into errors when data are truncated upon insertion, so Django highly recommends activating a strict mode for MySQL to prevent data loss (either STRICT_TRANS_TABLES or STRICT_ALL_TABLES).
If you need to customize the SQL mode, you can set the sql_mode variable like other MySQL options: either in a config file or with the entry 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" in the OPTIONS part of your database configuration in DATABASES.
MySQL 5.7 이상부터 sql_mode 옵션으로 STRICT_TRANS_TABLES 또는 STRICT_ALL_TABLES 가 있다고 한다.
장고는 데이터 손실을 방지하기 위해 위 옵션을 추가하는 것을 매우 추천한다고 한다.
장고 문서에 따라 장고 프로젝트 내 settings.py (또는 DB 세팅을 넣어놓은 파일)에 'OPTIONS"라는 행을 하나 만들고
'init_command': "SET sql_mode='STRICT_TRANS_TABLES' 을 넣어주면 위 메세지는 없어진다.
DATABASES = { 'default': { 'ENGINE' : 'django.db.backends.mysql', 'NAME':'데이터베이스 명칭', 'USER':'DB 진입 유저 아이디', 'PASSWORD':'DB 진입 유저 비밀번호', 'HOST':'호스트 IP', 'PORT':'포트번호', 'OPTIONS': { 'init_command' : "SET sql_mode='STRICT_TRANS_TABLES'", } }, }
끝!
'Developer > Posting' 카테고리의 다른 글
Jenkins Port 변경하기_최신판 (젠킨스 2.332 버전 이상이라면 봐야함) (0) | 2022.05.03 |
---|---|
Error: Your Command Line Tools (CLT) does not support macOS 11. (0) | 2021.05.31 |
Sentry(센트리) 튜토리얼: 코드 에러를 적극적으로 잡아보자 (0) | 2021.03.21 |
Django Admin을 가볍게 써본 기억 정리_10분 내 맛보는 법 (0) | 2021.03.07 |
https로 만들어봅시다! - Nginx 체인 인증서(SSL) 구매 및 적용 (0) | 2021.02.21 |