Raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)

10,595

Solution 1

Try to Install MySQL /Connector Python from https://dev.mysql.com/downloads/connector/python/8.0.html and also install using below command.

pip install mysql-connector-python

You can make settings for ENGINE in seeting.py as below.

    DATABASES = {
    'default': {
        'NAME': 'user_data',
        'ENGINE': 'mysql.connector.django',
        'USER': 'mysql_user',
        'PASSWORD': 'password',
        'OPTIONS': {
          'autocommit': True,
        },
    }
}

Then migrate using manage.py migrate It worked for me I hope that same for you.

Solution 2

Try to change the version of your Django and mysqlclient, I now use mysqlclient==1.3.12 and Django==2.0.5.

Solution 3

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

Solution 4

Django 2.1 does not support Mysql 5.5 yet.

Share:
10,595
Cyrus
Author by

Cyrus

Advanced Android engineer from China with 7 years in developing Android software. Proficient in using Java, Kotlin and most of design patter. Familiar with MVM,MVVP and have abundant experience in architecture design. Skilled use of various Unit Test Tools to write robust, extendable, reuseable code. 1 year experience as a team leader.

Updated on June 16, 2022

Comments

  • Cyrus
    Cyrus almost 2 years

    I have google this question . there plenty of similar problems , but i can't find proper answer.

    This is details of error Log :

    Traceback (most recent call last):
      File "manage.py", line 15, in <module>
        execute_from_command_line(sys.argv)
      File "d:\django\django\core\management\__init__.py", line 381, in execute_from_command_line
        utility.execute()
      File "d:\django\django\core\management\__init__.py", line 375, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "d:\django\django\core\management\base.py", line 288, in run_from_argv
        self.execute(*args, **cmd_options)
      File "d:\django\django\core\management\base.py", line 335, in execute
        output = self.handle(*args, **options)
      File "d:\django\django\core\management\commands\migrate.py", line 200, in handle
        fake_initial=fake_initial,
      File "d:\django\django\db\migrations\executor.py", line 91, in migrate
        self.recorder.ensure_schema()
      File "d:\django\django\db\migrations\recorder.py", line 57, in ensure_schema
        raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
    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"))
    

    This is settings.py

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'test',
            'USER': '*****',
            'PASSWORD': '****',
            'HOST': '**.***.***.**',
            'PORT': '3306',
        }
    }
    

    This is my models.py

    from django.db import models
    
    
    class Test(models.Model):
        _name = models.CharField(max_length=20, default="aaa")
        _score = models.CharField(max_length=20, default="DDD")
    

    This is my migrations file:0001_initial.py

    # Generated by Django 2.1.dev20180329192554 on 2018-04-03 04:11
    
    from django.db import migrations, models
    
    
    class Migration(migrations.Migration):
    
        initial = True
    
        dependencies = [
        ]
    
        operations = [
            migrations.CreateModel(
                name='Test',
                fields=[
                    ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                    ('name', models.CharField(default='aaa', max_length=20)),
                    ('score', models.CharField(default='DDD', max_length=20)),
                ],
            ),
        ]
    

    Mysql version : mysql Ver 14.14 Distrib 5.5.53, for linux2.6 (x86_64) using readline 5.1

    Those the pkgs about mysql

    enter image description here

    Who has ideas for this problem , Thanks for any help.

    • Mehrdad Pedramfar
      Mehrdad Pedramfar about 6 years
      can you share us your migration file? also the mysql package you use.
    • Cyrus
      Cyrus about 6 years
      @mehrdad-pedramfar I have add the file to my question.
    • Cyrus
      Cyrus about 6 years
      @mehrdad-pedramfar what is mysql package or how can i get mysql package info ? Thank you.
    • Mehrdad Pedramfar
      Mehrdad Pedramfar about 6 years
    • Cyrus
      Cyrus about 6 years
      @mehrdad-pedramfar there a lot of pkgs about mysql , I have post pic about mysql pkgs on my question.
    • anjaneyulubatta505
      anjaneyulubatta505 about 6 years
    • tread
      tread over 5 years
      @Cyrus Please post your answer
  • hellow
    hellow over 5 years
    Can you please provide a link to the documentation where you took this?
  • tread
    tread over 5 years
    You can check docs from above commented link: Django supports MySQL 5.5 and higher. docs.djangoproject.com/en/2.0/ref/databases/#mysql-notes
  • Thiago Elias
    Thiago Elias almost 5 years
    I understand why people downvoted your answer, but at the same time, this was the only option for me. I was using 2.1, but unfortunately, updating our customer's database was not an option, so Django==2.0.5 with mysqlclient==1.4.2 were the solution for this.
  • Juan García
    Juan García over 4 years
    I ran into the same problem. Python server version is 3.4 so I had to downgrade to django==2.0.13 and mysqlclient==1.3.14.