update db create models

This commit is contained in:
2026-08-10 12:58:01 +05:30
parent 1798d5e4de
commit 1e6e23359a

View File

@@ -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