django mysql connector_MySQL Connector / Python作为Django引擎?
即使經過數小時和數小時的谷歌搜索,也無法找到答案.搜索堆棧溢出.我向你們保證,我已經看到了所有可能被視為相關的答案,但這些答案都沒有解決我所面臨的問題.無需再費周折 –
目前在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.
總結
以上是生活随笔為你收集整理的django mysql connector_MySQL Connector / Python作为Django引擎?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: visual studio code p
- 下一篇: python decorator. de