How does Flask-SQLAlchemy create_all discover the models to create?

前端 未结 2 986
闹比i
闹比i 2020-12-28 10:16

Flask-SQLAlchemy\'s db.create_all() method creates each table corresponding to my defined models. I never instantiate or register instances of the models. They

2条回答
  •  伪装坚强ぢ
    2020-12-28 11:07

    You need to call create_all() in the same module as all the models are in. If they are in separate modules, you need to import them all before calling create_all(). SQLAlchemy looks at what models have been subclassed from db.Model, and it will only see models that have been imported. It will create the corresponding table for each model. Also explained here.

提交回复
热议问题