我有带命令的文件,与模型分开。我将所有模型从models
导入到starter
文件后才执行模型。
db = SQLAlchemy(app)
from models import *
try:
argv = sys.argv[1]
argv == '--run' and app.run()
argv == '--create' and db.create_all()
但对我来说这很模糊。我走遍了Flask-Sqlalchemy源代码。我看到了:
def get_tables_for_bind(self, bind=None):
"""Returns a list of all tables relevant for a bind."""
result = []
for table in self.Model.metadata.tables.itervalues():
if table.info.get('bind_key') == bind:
result.append(table)
return result
我理解self.Model
是:
def make_declarative_base(self):
"""Creates the declarative base."""
base = declarative_base(cls=Model, name='Model',
mapper=signalling_mapper,
metaclass=_BoundDeclarativeMeta)
base.query = _QueryProperty(self)
return base
我是否有更明确的方法来指定执行模型?以及self.Model
如何知道必须执行哪些表(导入后)?