Flask-SQLAlchemy create_all()

本秂侑毒 提交于 2019-12-01 01:54:31

dbManager will not know about the models you define in other modules unless they are imported before running create_all.

In a real application this shouldn't matter because running the flask app should set up the db and import views/blueprints to register them. Since the views use the models, the models are indirectly imported and are available to the dbManager.

Either import your models in the blogconfig module after creating the dbManager instance, or change the order of you shell commands to be

>>> from blogconfig import dbManager
>>> import models
>>> dbManager.create_all()

SQLAlchemy will only create tables, the database must already exist, which is why you're seeing the other error when you delete the database.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!