sqlalchemy.exc.NoSuchModuleError: Can‘t load plugin: sqlalchemy.dialects:MySQL.pyMySQL
阿新 • • 發佈:2020-12-23
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