在执行python models.py 中报错
来源:3-8 .管理员-登录日志-操作日志数据模型设计
JoannaMua
2017-08-18
Traceback (most recent call last):
File "models.py", line 183, in <module>
db.create_all()
File "C:\Users\Administrator\movie_venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 1007, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "C:\Users\Administrator\movie_venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 999, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "C:\Users\Administrator\movie_venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 941, in get_engine
return connector.get_engine()
File "C:\Users\Administrator\movie_venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 543, in get_engine
self._engine = rv = sqlalchemy.create_engine(info, **options)
File "C:\Users\Administrator\movie_venv\lib\site-packages\sqlalchemy\engine\__init__.py", line 387, in create_engine
return strategy.create(*args, **kwargs)
File "C:\Users\Administrator\movie_venv\lib\site-packages\sqlalchemy\engine\strategies.py", line 80, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "C:\Users\Administrator\movie_venv\lib\site-packages\sqlalchemy\dialects\mysql\mysqldb.py", line 110, in dbapi
return __import__('MySQLdb')
ModuleNotFoundError: No module named 'MySQLdb'
老师如果需要更多代码,请提示我需要给出哪段代码,感谢!
1回答
-
同学你好,默认的mysqldb不存在,使用pymysql模块,在头部这样引入:
from flask import Flask from flask_sqlalchemy import SQLAlchemy import pymysql app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:root@127.0.0.1:8889/movie" app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True db = SQLAlchemy(app)
042017-08-19
相似问题