fantasy/__init__.py
def smart_database(app):
    """尝试对数据库做初始化操作"""

    from sqlalchemy.engine.url import make_url
    from sqlalchemy_utils import database_exists, create_database

    # 如果数据库不存在，则尝试创建数据
    dsn = make_url(app.config['SQLALCHEMY_DATABASE_URI'])
    if not database_exists(dsn):
        create_database(dsn)
        pass
    pass
def smart_database(app):
    """尝试对数据库做初始化操作"""

    from sqlalchemy.engine.url import make_url
    from sqlalchemy_utils import database_exists, create_database

    # 如果数据库不存在，则尝试创建数据
    dsn = make_url(app.config['SQLALCHEMY_DATABASE_URI'])
    if not database_exists(dsn):
        create_database(dsn)
        pass
    pass
尝试对数据库做初始化操作