即使经过数小时和数小时的谷歌搜索,也无法找到答案.搜索堆栈溢出.我向你们保证,我已经看到了所有可能被视为相关的答案,但这些答案都没有解决我所面临的问题.无需再费周折 –
目前在shell中我可以这样做:
Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.sysconfig import get_python_lib
>>> print get_python_lib()
/usr/lib/python2.7/dist-packages
>>> import mysql.connector
>>> db = mysql.connector.connect(user='root', password='test123', host='127.0.0.1', database='mydb')
>>> db
验证我已安装此模块.但是,当我尝试转到settings.py文件以设置DATABASE ENGINE时
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'mydb',
'USER': 'root',
'PASSWORD': 'test123',
'HOST': '127.0.0.1',
'PORT': '3306'
}
}
并尝试启动我的服务器我一直收到错误:
django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django'
isn't an available database backend.
不知道如何解决这个问题.我在Django版本1.9.7上,Python版本显示在上面的代码片段中
使用’mysql.connector.django’与使用’django.db.backends.mysql’之间有什么区别?
最佳答案
What would be the difference between using ‘mysql.connector.django’
vs. using ‘django.db.backends.mysql’ ?
从前者开始是推荐的方法,而后者则不是.前者完全支持,但后者需要1.1.x版本,django文档中还有一个警告,即更新版本的django可能无法完全支持它.
The Python Database API is described in PEP 249. MySQL has three
prominent drivers that implement this API:
MySQLdb is a native driver that has been developed and supported for
over a decade by Andy Dustman. mysqlclient is a fork of MySQLdb which
notably supports Python 3 and can be used as a drop-in replacement for
MySQLdb. At the time of this writing, this is the recommended choice
for using MySQL with Django. MySQL Connector/Python is a pure Python
driver from Oracle that does not require the MySQL client library or
any Python modules outside the standard library. All these drivers are
thread-safe and provide connection pooling. MySQLdb is the only one
not supporting Python 3 currently.
In addition to a DB API driver, Django needs an adapter to access the
database drivers from its ORM. Django provides an adapter for
MySQLdb/mysqlclient while MySQL Connector/Python includes its own.