Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

python - Django and mysql problems on Mavericks

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...