【问题标题】:Raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)Raise MigrationSchemaMissing("无法创建 django_migrations 表 (%s)" % exc)
【发布时间】:2018-09-12 11:27:53
【问题描述】:

我有谷歌这个问题。有很多类似的问题,但我找不到正确的答案。

这是错误日志的详细信息:

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"))

这是 settings.py

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

这是我的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")

这是我的迁移文件: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 版本:mysql Ver 14.14 Distrib 5.5.53,适用于 linux2.6 (x86_64) 使用 readline 5.1

那些关于 mysql 的 pkgs

谁有这个问题的想法,谢谢你的帮助。

【问题讨论】:

  • 您能与我们分享您的迁移文件吗?还有你使用的 mysql 包。
  • @mehrdad-pedramfar 我已将文件添加到我的问题中。
  • @mehrdad-pedramfar 什么是 mysql 包或如何获取 mysql 包信息?谢谢。
  • @mehrdad-pedramfar 有很多关于 mysql 的 pkgs,我在我的问题上发布了关于 mysql pkgs 的图片。

标签: python django python-3.x django-models


【解决方案1】:

尝试从https://dev.mysql.com/downloads/connector/python/8.0.html 安装 MySQL /Connector Python 并使用以下命令进行安装。

pip install mysql-connector-python

您可以在seeting.py中对ENGINE进行如下设置。

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

然后使用manage.py migrate 进行迁移 它对我有用,我希望对你也一样。

【讨论】:

    【解决方案2】:

    尝试更改您的Djangomysqlclient 的版本,我现在使用mysqlclient==1.3.12Django==2.0.5

    【讨论】:

    • 我理解为什么人们不赞成您的回答,但与此同时,这对我来说是唯一的选择。我使用的是 2.1,但不幸的是,无法更新我们客户的数据库,因此 Django==2.0.5mysqlclient==1.4.2 是解决此问题的方法。
    • 我遇到了同样的问题。 Python 服务器版本是 3.4,所以我不得不降级到 django==2.0.13 和 mysqlclient==1.3.14。
    【解决方案3】:
    from django.db.backends.mysql.base import DatabaseWrapper 
    DatabaseWrapper.data_types['DateTimeField'] = 'datetime'
    

    【讨论】:

      【解决方案4】:

      Django 2.1 还不支持 Mysql 5.5。

      【讨论】:

      【解决方案5】:

      对于Django 3.2,我必须将mysql5.5升级到5.7

      【讨论】:

        猜你喜欢
        • 2016-08-10
        • 2018-11-21
        • 2022-10-03
        • 2018-07-13
        • 2018-06-23
        • 2022-11-03
        • 2021-04-04
        • 2018-10-14
        • 1970-01-01
        相关资源
        最近更新 更多