본문 바로가기

Dev/Django

django3.x-mysql 5.1 migrate 오류

728x90
반응형

새로운 프로젝트를 하면서 파이썬을 구동하다 보니... 자연스럽게 당고(Django)를 하게 되었다...

 

하면서 DB 연동부터 삽질이 시작..

 

Django에서는 ORM을 지원해주기 때문에 makemigrations 후에 migrate를 해줘야 한다.

 

mkamigrations는 정상적으로 처리 되었는데

 

 

python manage.py migrate

위의 명령어를 치니 아래와 같은 오류가....

django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
use near '(6) NOT NULL)' at line 1"))

사용하고 있는 버전은 Django 3.0.3에 Mysql은 5.1.7 연동중에 호환성에 문제가 있는것으로 보인다.

 

위의 문제가 발생할때는

from django.db.backends.mysql.base import DatabaseWrapper
DatabaseWrapper.data_types['DateTimeField'] = 'datetime'

위의 datatie 필드의 타입을 변경해주는 코드를 입력하면 된다.

그러면 오류 없이 동작

(Django) D:\pythonProject\Django\ToDoList>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, my_to_do_app, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying my_to_do_app.0001_initial... OK
  Applying sessions.0001_initial... OK

 

참고로 makemigrations를 할때 settings.py의 DB 세팅 값인 default 부문에서

DATABASES = {} 영역에 주석이 있으면 오류가 난다... 

그러니 주석없이 처리하시길...

 

 

728x90
반응형

'Dev > Django' 카테고리의 다른 글

django model Table 삭제 방법  (1) 2020.10.20
내부망 접속 방법  (0) 2020.10.19
Django-DATABASES init_command 멀티 설정  (0) 2020.08.31
Django-Mysql 엔진 설정  (0) 2020.08.31
Django-한국시간 설정  (0) 2020.08.31