将django连接到mysql时出错

时间:2014-06-16 19:55:34

标签: python mysql django

当我尝试将我的django项目连接到mysql数据库时,我收到以下错误

manage.py syncdb

Traceback (most recent call last):
  File "C:\Django-1.3.3\build\scripts-2.7\collegetree\manage.py", line 14, in <module>
    execute_manager(settings)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 7, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
  File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 6, in <module>
    from django.db import models
  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 78, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "C:\Python27\lib\site-packages\django\db\utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:\Python27\lib\site-packages\django\db\utils.py", line 33, in load_backend
    return import_module('.base', backend_name)
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 14, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

安装一些软件包时,我的django自动从1.3.3开始更新到1.6版本。我卸载了1.6并重新安装了1.3.3 从那以后我开始面对这个问题。

1 个答案:

答案 0 :(得分:0)

按照以下方式在ubuntu上安装Mysql ..

  

$ sudo apt-get install mysql-server
  $ sudo apt-get install mysql-client

然后运行此命令来检查mysql是否正在运行

  

$ sudo netstat -tap | grep mysql

然后关于这个错误..

对于virtualenv或项目之外,您需要python mysql连接。使用

获取它
  

apt-get install python-mysqldb

希望这会对你有所帮助