django_migrations table ((1064, "You have an error in your SQL syntax; check the manual that corresp

(venv) D:\zz\PycharmProjects\zilv>python manage.py migrate
System check identified some issues:

WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
        HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you
activate it. See: https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: admin, auth, autonomy, contenttypes, sessions
Running migrations:
Traceback (most recent call last):
  File "C:\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "C:\Python\Python37\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\cursors.py", line 170, in execute
    result = self._query(query)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\cursors.py", line 328, in _query
    conn.query(q)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\connections.py", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\connections.py", line 732, in _read_query_result
    result.read()
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\connections.py", line 1075, in read
    first_packet = self.connection._read_packet()
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\connections.py", line 684, in _read_packet
    packet.check_error()
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (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")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python\Python37\lib\site-packages\django\db\migrations\recorder.py", line 55, in ensure_schema
    editor.create_model(self.Migration)
  File "C:\Python\Python37\lib\site-packages\django\db\backends\base\schema.py", line 312, in create_model
    self.execute(sql, params or None)
  File "C:\Python\Python37\lib\site-packages\django\db\backends\base\schema.py", line 133, in execute
    cursor.execute(sql, params)
  File "C:\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 100, in execute
    return super().execute(sql, params)
  File "C:\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Python\Python37\lib\site-packages\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "C:\Python\Python37\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\cursors.py", line 170, in execute
    result = self._query(query)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\cursors.py", line 328, in _query
    conn.query(q)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\connections.py", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\connections.py", line 732, in _read_query_result
    result.read()
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\connections.py", line 1075, in read
    first_packet = self.connection._read_packet()
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\connections.py", line 684, in _read_packet
    packet.check_error()
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "D:\zz\PycharmProjects\zilv\venv\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
django.db.utils.ProgrammingError: (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 N
ULL)' at line 1")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python\Python37\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python\Python37\lib\site-packages\django\core\management\base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "C:\Python\Python37\lib\site-packages\django\core\management\base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Python\Python37\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "C:\Python\Python37\lib\site-packages\django\db\migrations\executor.py", line 91, in migrate
    self.recorder.ensure_schema()
  File "C:\Python\Python37\lib\site-packages\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 y
our MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1"))

最终定位到的问题原因 是 MySQL 版本问题, 

Django2.1不再支持MySQL5.5,必须5.6版本以上

1)降低 Django版本

降低 Django 版本指令:

pip install Django==2.0.0

2)MySQL 升级

`django.db.utils.ProgrammingError: (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 '...'.")` 这个错误是Django在使用数据库时,生成的SQL语句存在语法错误,导致MySQL数据库无法正确解析执行。1064错误是MySQL数据库中一个常见的错误,通常是因为SQL查询语句的语法不正确。 在Django中,当你使用Django的ORM(对象关系映射)系统来编写数据库查询时,Django会自动为你生成SQL语句。如果你的模型定义、查询语句或者数据库迁移文件中有不正确的SQL语法,就可能出现这个错误。这个问题常见于以下几个方面: 1. 查询集使用不当:例如,在过滤(filter)查询中使用了错误的字段名或者没有正确使用Django的字段查找类型(如`__exact`、`__contains`等)。 2. 数据库迁移错误:在执行数据库迁移时,如果迁移文件中的某些操作语法不正确,也会产生这个错误。 3. 拼写错误:在定义模型的字段或在编写SQL查询时,字段名拼写错误,或者关键字、函数名写错也会引发此错误。 4. 特殊字符或保留字:如果你在字段名或表名中使用了数据库的特殊字符或保留字,而没有正确处理(如使用反引号`来包围字段名),也会导致语法错误。 解决这类问题一般需要按照错误提示中的“near '...'”部分仔细检查SQL语句,确认是否有拼写错误、缺少括号、错误的语法结构等。如果是在Django ORM中遇到的问题,建议查看Django的官方文档学习正确的查询方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值