【问题标题】:Django mysql error in ubuntuUbuntu中的Django mysql错误
【发布时间】:2014-02-24 15:28:01
【问题描述】:

我已经开始学习 django 和 python,而且我是使用 ubuntu 的新手。对于我的第一个程序,我需要 mysql,所以我已经安装了它,当我使用 mysql 命令时,我得到了这个结果。

user@ubuntu:~$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.5.34-0ubuntu0.12.10.1 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

但是当我根据 django 站点指令运行这个命令时

python manage.py syncdb

我有这个错误

  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

此外,我在 settings.py 文件中做了一些修改,如下所示:

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

为什么会这样?我该如何解决?

【问题讨论】:

    标签: mysql django ubuntu django-models mysql-python


    【解决方案1】:

    错误告诉你问题出在哪里:你没有安装 Django 需要与数据库对话的 MySQLdb 库。

    您可以使用pip install mysql-pythonsudo apt-get install python-mysqldb 安装它。

    【讨论】:

    • 有一些系统依赖。使用我给出的第二个选项可能更好,因为 apt-get 将为您安装依赖项。
    • 我做到了,但在运行python manage.py syncdb 命令后仍然出现之前的错误。我应该在 manage.py 中做些什么吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 2016-10-24
    • 1970-01-01
    相关资源
    最近更新 更多