加载 MySQLdb 模块时出错“您安装了 mysqlclient 还是 MySQL-python?"

2021-12-02 00:00:00 python django mysql phpmyadmin

我在使用 python34 的 django 项目中使用 windows 10 命令行,但是,我在使用 SQL 时遇到了困难.

I am using windows 10 command line for a django project using python34 however, I am facing difficulties with SQL.

我已经使用 pip install mysqlclient==1.3.5 安装了 mysqlclient 并找到了该文件以确保我没有错觉.然后我运行 python manage.py migrate 将表迁移到 SQL 数据库(我使用的是 phpmyadmin).但是,当命令返回...

I have already installed mysqlclient using pip install mysqlclient==1.3.5 and located the file to make sure I was not delusional. I then ran python manage.py migrate to migrate the tables to the SQL database (I am using phpmyadmin). However when the command returned with...

 File "C:Usersuserenvlibsite-packagesdjangodbackendsmysqlase.py", line 30, in <module>
    'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?

我知道这样的问题已经存在,但似乎没有一种解决方案对尝试产生任何影响.提前致谢.

I am aware that questions like these already exist, but not one solution seems to have made any impact on attempts. Thank you in advance.

推荐答案

pip install pymysql

然后,在你的项目源目录中编辑__init__.py文件(与settings.py相同)

Then, edit the __init__.py file in your project origin dir(the same as settings.py)

添加:

import pymysql

pymysql.install_as_MySQLdb()

相关文章