当前位置: 代码迷 >> 综合 >> sqlalchemy.exc.NoSuchModuleError: Can‘t load plugin: sqlalchemy.dialects:MySQL.pyMySQL
  详细解决方案

sqlalchemy.exc.NoSuchModuleError: Can‘t load plugin: sqlalchemy.dialects:MySQL.pyMySQL

热度:70   发布时间:2023-11-21 09:47:11.0

flask框架之数据库配置问题

config配置文件下报错,代码如下:

# -*- coding: utf-8 -*-
# @Author: Small-J
# @Date : 2020/12/22# 该文件存放数据库配置项USERNAME = 'root'
PASSWORD = 'root'
HOST = '127.0.0.1'
PORT = '3306'
DATABASE = 'JobData'DB_URL = 'MySQL+pyMySQL://{}:{}@{}:{}/{}?charset=utf8'.format(USERNAME, PASSWORD, HOST, PORT, DATABASE)SQLALCHEMY_DATABASE_URI = DB_URL# 动态追踪修改设置,如未设置只会提示警告
SQLALCHEMY_TRACK_MODIFICATIONS = False# 查询时会显示原始sql语句
SQLALCHEMY_ECHO = True

报错如下:

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:MySQL.pyMySQL
  • 意思是找不到相对应的插件

解决方案如下

  • 将DB_URL的路径改成小写形式
# -*- coding: utf-8 -*-
# @Author: Small-J
# @Date : 2020/12/22# 该文件存放数据库配置项USERNAME = 'root'
PASSWORD = 'root'
HOST = '127.0.0.1'
PORT = '3306'
DATABASE = 'JobData'DB_URL = 'mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8'.format(USERNAME, PASSWORD, HOST, PORT, DATABASE)SQLALCHEMY_DATABASE_URI = DB_URL# 动态追踪修改设置,如未设置只会提示警告
SQLALCHEMY_TRACK_MODIFICATIONS = False# 查询时会显示原始sql语句
SQLALCHEMY_ECHO = True
  相关解决方案