MySQL Connector / Python作为Django引擎?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了MySQL Connector / Python作为Django引擎?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2335字,纯文字阅读大概需要4分钟。
内容图文
![MySQL Connector / Python作为Django引擎?](/upload/InfoBanner/zyjiaocheng/903/2e36feb407a54c4eac4d292fdedfad0a.jpg)
即使经过数小时和数小时的谷歌搜索,也无法找到答案.搜索堆栈溢出.我向你们保证,我已经看到了所有可能被视为相关的答案,但这些答案都没有解决我所面临的问题.无需再费周折 –
目前在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
<mysql.connector.connection.MySQLConnection object at 0x7fd3a80536d0>
验证我已安装此模块.但是,当我尝试转到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.
内容总结
以上是互联网集市为您收集整理的MySQL Connector / Python作为Django引擎?全部内容,希望文章能够帮你解决MySQL Connector / Python作为Django引擎?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。