本文介绍了如何使用pymysql作为驱动程序配置Django?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Django的新手.整个下午浪费我的时间来配置MySQL引擎.我对数据库引擎和数据库驱动程序感到非常困惑. 引擎也是驱动程序吗?所有的教程都说ENGINE应该是'django.db.backends.mysql',但是ENGINE如何决定使用哪个驱动程序来连接MySQL?

I'm new to Django. It wasted me whole afternoon to config the MySQL engine. I am very confused about the database engine and the database driver. Is the engine also the driver? All the tutorial said that the ENGINE should be 'django.db.backends.mysql', but how the ENGINE decide which driver is used to connect MySQL?

每当它说'django.db.backends.mysql'时,可悲的是我无法安装MySQLDb和mysqlclient,但是已经安装了PyMysql和官方的 mysql连接器2.1.3 .如何将驱动程序设置为PyMysql或mysql连接器?

Every time it says 'django.db.backends.mysql', sadly I can't install MySQLDb and mysqlclient, but PyMysql and the official mysql connector 2.1.3 has been installed. How could I set the driver to PyMysql or mysql connector?

非常感谢!

  • OS:OS X Al Capitan
  • Python:3.5
  • Django:1.9

此问题尚未解决: ENGINE 还是 DRIVER 吗?

This question is not yet solved:Is the ENGINE also the DRIVER?

推荐答案

您可以导入pymsql,使其显示为MySQLdb .您需要先 运行django代码,然后将其放入您的manage.py文件

You can import pymsql so it presents as MySQLdb. You'll need to do this before any django code is run, so put this in your manage.py file

import pymysql
pymysql.install_as_MySQLdb()

这篇关于如何使用pymysql作为驱动程序配置Django?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:14