使用mysql在django上的syncdb错误

syncdb error on django using mysql

我是新来的。我在用Ubuntu 13.04

尽管我通过phpmyadmin创建了数据库,并在settings.py中输入了凭证。但是当我在控制台里打字的时候

python manage.py syncdb

我有这个错误

Traceback (most recent call last):

File"manage.py", line 10, in

execute_from_command_line(sys.argv)

File"/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 453, in execute_from_command_line

1
utility.execute()

File"/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 392, in execute

1
self.fetch_command(subcommand).run_from_argv(self.argv)

File"/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 272, in fetch_command

1
klass = load_command_class(app_name, subcommand)

File"/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 77, in load_command_class

1
module = import_module('%s.management.commands.%s' % (app_name, name))

File"/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module

1
__import__(name)

File"/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 8, in

1
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal

File"/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", line 9, in

1
from django.db import models

File"/usr/local/lib/python2.7/dist-packages/django/db/init.py", line 40, in

1
backend = load_backend(connection.settings_dict['ENGINE'])

File"/usr/local/lib/python2.7/dist-packages/django/db/init.py", line 34, in getattr

1
return getattr(connections[DEFAULT_DB_ALIAS], item)

File"/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 93, in getitem

1
backend = load_backend(db['ENGINE'])

File"/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 27, in load_backend

1
return import_module('.base', backend_name)

File"/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module

1
__import__(name)

File"/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 17, in

1
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)

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

我试过在settings.py中为db name提供扩展名,但它不起作用。请提出建议。谢谢!


或者你可以这样做:

1
sudo apt-get install python-mysqldb

您的虚拟环境中是否安装了MySQL?

尝试

1
pip install MySQL-python