update db create models
This commit is contained in:
@@ -10,7 +10,9 @@ def create_app():
|
|||||||
# Initialize extensions
|
# Initialize extensions
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
migrate.init_app(app, db)
|
migrate.init_app(app, db)
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
|
import_all_models()
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
# Initialize Logger
|
# Initialize Logger
|
||||||
@@ -29,6 +31,19 @@ def create_app():
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
def import_all_models():
|
||||||
|
"""
|
||||||
|
Dynamically imports every module inside app/models/
|
||||||
|
so that db.create_all() knows about all tables (User, etc).
|
||||||
|
"""
|
||||||
|
import pkgutil
|
||||||
|
import importlib
|
||||||
|
import app.models as models_package
|
||||||
|
|
||||||
|
for _, module_name, _ in pkgutil.iter_modules(models_package.__path__):
|
||||||
|
importlib.import_module(f"app.models.{module_name}")
|
||||||
|
|
||||||
|
|
||||||
def register_blueprints(app):
|
def register_blueprints(app):
|
||||||
from app.routes.auth import auth_bp
|
from app.routes.auth import auth_bp
|
||||||
from app.routes.user_routes import user_bp
|
from app.routes.user_routes import user_bp
|
||||||
|
|||||||
Reference in New Issue
Block a user