小牛的Django和mysql问题 [英] Django and mysql problems on Mavericks

查看:1161
本文介绍了小牛的Django和mysql问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Mac OSX 10.9小牛。我试图在python 3下运行django。因为我正在运行Python 3,我必须从mysql devs获得官方连接器这里给了它在shell中的一个快速测试,它的工作。



我跑了$ code> python manage.py runserver 与mysql.connector.django作为引擎已经看到一个例子这里,我收到这个错误:

  django.core.exceptions.ImproperlyConfigured:'mysql.connector.django'不是可用的数据库后端。 
尝试使用'django.db.backends.XXX',其中XXX是以下之一:
u'mysql',u'oracle',u'postgresql_psycopg2',u'sqlite3'
错误是:没有名为mysql.connector.django.base的模块

所以我切换回默认使用django.db.backends.mysql作为我的引擎,我得到这个错误:

  django.core.exceptions.ImproperlyConfigured:加载MySQLdb模块时出错:没有名为MySQLdb的模块

我不知道如何进行。我不能安装MySQLdb,因为我在python3下运行我的django安装,并且它不受支持,但我绝对缺少这个连接器的东西。

解决方案

对于python 2.7,3.3+,有一个名为 mysqlclient 的驱动程序,可用于django 1.8

  pip install mysqlclient 

在您的设置中

  DATABASES = {
'default':{
'NAME' :'',
'ENGINE':'django.db.backends.mysql',
'USER':'',
'PASSWORD':'',
}
}

这是关于mysql驱动程序的官方django文档:



https://docs.djangoproject.com /en/1.8/ref/databases/#mysql-db-api-drivers


I'm running Mac OSX 10.9 Mavericks. I'm trying to run django under python 3. Because I'm running Python 3 I have to get the official connector from the mysql devs here gave it a quick test in the shell and it works.

I ran python manage.py runserver with "mysql.connector.django" as the engine having seen an example here and I got this error:

django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named mysql.connector.django.base

So I switch back to the default using "django.db.backends.mysql" as my engine and I get this error:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I have no idea how to proceed. I can't install MySQLdb because I'm running my django install under python3 and it's unsupported, but I'm definitely missing something with this connector.

解决方案

For python 2.7, 3.3+ there is a driver called mysqlclient that works with django 1.8

pip install mysqlclient

And in your settings

DATABASES = {
    'default': {
        'NAME': '',
        'ENGINE': 'django.db.backends.mysql',
        'USER': '',
        'PASSWORD': '',      
    }
}

Here's the official django documentation about the mysql drivers:

https://docs.djangoproject.com/en/1.8/ref/databases/#mysql-db-api-drivers

这篇关于小牛的Django和mysql问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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