• ModuleNotFoundError: No module named 'MySQLdb'


    现象

    出现:ModuleNotFoundError: No module named 'MySQLdb'

    (venv) D:\pycharm\Django_01\myapp>python manage.py runserver 0.0.0.0:8800
    Watching for file changes with StatReloader
    Exception in thread django-main-thread:
    Traceback (most recent call last):
      File "D:\pycharm\Django_01\venv\lib\site-packages\django\db\backends\mysql\base.py", line 16, in <module>
        import MySQLdb as Database
    ModuleNotFoundError: No module named 'MySQLdb'
    
    The above exception was the direct cause of the following exception:

    背景

    更换django项目的默认数据库为mysql,然后使用命令行(python manage.py runserver 0.0.0.0:8800)再启动,报错

    解决方案

    安装mysql的客户端

    pip install mysqlclient

    再次启动,则是ok

    (venv) D:\pycharm\Django_01\myapp>python manage.py runserver 0.0.0.0:8800
    Watching for file changes with StatReloader
    Performing system checks...
    
    System check identified no issues (0 silenced).
    
    You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
    Run 'python manage.py migrate' to apply them.
    March 22, 2022 - 19:01:41
    Django version 3.0, using settings 'myapp.settings'
    Starting development server at http://0.0.0.0:8800/
    Quit the server with CTRL-BREAK.
  • 相关阅读:
    MySQL中IS NULL、IS NOT NULL、!=不能用索引?胡扯!
    市值TOP10,人类进化及中美坐标
    倒序切片
    对list进行切片
    Python之定义可变参数
    Python之递归函数
    Python之“可变”的tuple
    Python之创建单元素tuple
    Python中Unicode字符串
    Pycharm配置autopep8让Python代码更符合pep8规范
  • 原文地址:https://www.cnblogs.com/Durant0420/p/16040856.html
Copyright © 2020-2023  润新知