Django迁移错误_mysql_exceptions.ProgrammingError:(1064,"您的SQL语法有错误 [英] Django migrate error _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax

查看:703
本文介绍了Django迁移错误_mysql_exceptions.ProgrammingError:(1064,"您的SQL语法有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR:python版本冲突,我认为我下载并编译的python(3.6)无法使用此软件包(libmysqlclient-dev)进行向mysql的迁移.只有系统默认的python(3.4)可以.

TL;DR: python versions conflicts, i think that the python i downloaded and compiled (3.6) can't use this package (libmysqlclient-dev) to make migrations to mysql. only the system's default python (3.4) can.

我的ubuntu服务器带有python 3.4,我所有的django工作和其他工作都依赖于3.6.我了解到升级系统python是一个坏主意,因此我编译了python 3.6(使用altinstall).

my ubuntu server came with python 3.4, all of my django work and other work depend on 3.6. i have learned that upgrading system python is a bad idea, so i compiled python 3.6 (with altinstall).

当我运行python3.6 manage.py migrate时,它给了我这个mysql错误:

when i ran python3.6 manage.py migrate it gave me this mysql error:

_mysql_exceptions.ProgrammingError:(1064,您的SQL语法有错误;请查看与MySQL服务器版本相对应的手册,以在第1行的'(6)NOT NULL)'附近使用正确的语法")

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

我尝试了虚拟环境和普通的python 3.6,两者都给出了相同的错误,并且确保安装了libmysqlclient-devmysqlclient.

i tried virtual environment and normal python 3.6, both gave the same error, and i made sure that libmysqlclient-dev and mysqlclient are installed.

此答案所示,问题出在libmysqlclient-dev上,因为它已安装通过apt-get而不是pip,所以我想它仅与默认的python(系统随附的3.4)兼容,否则我的编译后的python 3.6不允许使用它,因为当我使用python3创建了一个虚拟django项目时. 4(系统默认值),并在同一用户的同一mysql数据库上尝试python3.6 manage.py migrate,成功了!

as this answer suggests, the problem is with libmysqlclient-dev because it's installed via apt-get not pip so i guess it's only compatible with the default python (3.4 that came with the system) or my compiled python 3.6 isn't allowed to use it, because when i made a dummy django project with python3.4 (system's default) and attempted python3.6 manage.py migrate on the same mysql database with the same user, it worked!

再次:我的问题是手动编译的python 3.6无法使用apt-get已安装的libmysqlclient-dev,只有3.4可以

AGAIN: my problem is that the manually compiled python 3.6 can't use libmysqlclient-dev that has been installed by apt-get, only 3.4 can

参考:迁移时的Django MySQL错误

更新 我想出了一个解决方法,但是效率不高.我将Django降级为2.0.9,并且它(python manage.py migrate)正常工作.但是使用其他软件包可能会再次出现此问题.

UPDATE i came up with a work around but it's not efficient. i downgraded Django to 2.0.9 and it (python manage.py migrate) worked. but this problem could appear again with a different package.

推荐答案

Django 2.1.*需要MySQL 5.6或更高版本.它通过将DateTimeField映射到datetime(6)破坏了兼容性.

Django 2.1.* requires MySQL 5.6 or higher. It broke the compatibility by mapping DateTimeField to datetime(6).

您可以修补Django MySQL数据类型映射器.将其放在settings.py

You can patch Django MySQL data type mapper. Put this to the top of your settings.py

from django.db.backends.mysql.base import DatabaseWrapper
DatabaseWrapper.data_types['DateTimeField'] = 'datetime' # fix for MySQL 5.5

这篇关于Django迁移错误_mysql_exceptions.ProgrammingError:(1064,"您的SQL语法有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆