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