from flask import Flask from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy from sqlalchemy import MetaData from sqlalchemy.orm import DeclarativeBase class BaseModel(DeclarativeBase): pass convention = { "ix": "ix_%(column_0_label)s", "uq": "uq_%(table_name)s_%(column_0_name)s", "ck": "ck_%(table_name)s_%(constraint_name)s", "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", "pk": "pk_%(table_name)s" } def connect_db_with_app(): app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///db.sqlite3" db.init_app(app) migrate.init_app(app, db) metadata = MetaData(naming_convention=convention) app = Flask(__name__) db = SQLAlchemy(model_class=BaseModel, metadata=metadata) migrate = Migrate(render_as_batch=True)