Flask_sqlalchemy Create_all Without Having To Import Models
I am trying to understand how to set up a standalone script that calls create_all without having to import all my models into it. Below are the relevant files: db.py from flask_sql
Solution 1:
In a word, no. You will have to import those models before the call to create_all()
, one way or the other. The declarative classes build the Table
instances and add them to the MetaData
when the class itself is constructed. If the MetaData
contains no tables, create_all
will do nothing.
Put another way, "declaring models" does nothing unless those declarations are evaluated, so the module must be executed. Importing from it does just that.
Post a Comment for "Flask_sqlalchemy Create_all Without Having To Import Models"