django.core.exceptions.ImproperlyConfigured: 加载MySQLdb模块出错:找不到名为MySQLdb的模块。

14 浏览
0 Comments

django.core.exceptions.ImproperlyConfigured: 加载MySQLdb模块出错:找不到名为MySQLdb的模块。

尝试连接到MySQL数据库时遇到的问题。我也提供了我使用的数据库设置。

追溯(最近的调用最后):

文件“manage.py”,第10行,在中执行_from_command_line(sys.argv)

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py”,第453行,在execute_from_command_line中执行

utility.execute()

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py”,第392行,在execute中执行

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

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py”,第272行,在fetch_command中执行

klass = load_command_class(app_name, subcommand)

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py”,第77行,在load_command_class中执行

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

文件“/home/arundhati/Desktop/test/testprac/local/lib/python2.7/site-packages/django/utils/importlib.py”,第35行,在import_module中执行

__import__(name)

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py”,第8行,在中执行

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

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/sql.py”,第9行,在中执行

from django.db import models

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/__init__.py”,第40行,在中执行

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

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/__init__.py”,第34行,在__getattr__中执行

return getattr(connections[DEFAULT_DB_ALIAS], item)

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/utils.py”,第93行,在__getitem__中执行

backend = load_backend(db['ENGINE'])

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/utils.py”,第27行,在load_backend中执行

return import_module('.base', backend_name)

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/utils/importlib.py”,第35行,在import_module中执行

__import__(name)

文件“/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py”,第17行,在中执行

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

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

数据库设置:

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql', # 添加'postgresql_psycopg2'、'mysql'、'sqlite3'或'oracle'。

'NAME': 'ar_test_db', # 或者如果使用数据库文件,则为数据库文件路径

# 以下设置在sqlite3中不使用:

'USER': '',

'PASSWORD': '',

'HOST': '', # 对于通过域套接字连接到本地主机,为空;对于通过TCP连接到本地主机,为'127.0.0.1'。

'PORT': '', # 设置为空字符串以使用默认值。

}

}

非常感谢您的帮助!!

0