py3.6.2下,django 框架连接数据库的时候出现的

Traceback(mostrecentcalllast):File"/usr/local/lib/python3.6/site-packages/Django-1.11... Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/db/backends/mysql/base.py", line 26, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/db/models/base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/usr/local/lib/python3.6/site-packages/Django-1.11.4-py3.6.egg/django/db/models/base.py", line 331, in add_to_class
value.contribute_to_class(cls, name)
...
Did you install mysqlclient or MySQL-python?
展开
 我来答
匿名用户
2017-08-15
展开全部
方法/步骤

修改setting.py里面的DATABASES元组为
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'books', #你的数据库名称
'USER': 'root', #你的数据库用户名
'PASSWORD': '', #你的数据库密码
'HOST': '', #你的数据库主机,留空默认为localhost
'PORT': '3306', #你的数据库端口
}
}

INSTALLED_APPS = (
'books',#你的数据库名称
)

在mysql里面创建books数据库

检查配置是否有语法错误

使用python manage.py sqlall books 显示mysql语法

使用python manage.py syncdb同步模型中的数据库

创建成功!
追问
已经按照这个方式走过一边来着
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式