32 lines
949 B
Python
32 lines
949 B
Python
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
创建收藏表的数据库迁移脚本
|
|||
|
|
"""
|
|||
|
|
from src.flask_prompt_master import create_app, db
|
|||
|
|
from src.flask_prompt_master.models.favorites import Favorite
|
|||
|
|
|
|||
|
|
def create_favorites_table():
|
|||
|
|
"""创建收藏表"""
|
|||
|
|
app = create_app()
|
|||
|
|
|
|||
|
|
with app.app_context():
|
|||
|
|
try:
|
|||
|
|
# 创建表
|
|||
|
|
db.create_all()
|
|||
|
|
print("✅ 收藏表创建成功!")
|
|||
|
|
|
|||
|
|
# 验证表是否存在
|
|||
|
|
from sqlalchemy import inspect
|
|||
|
|
inspector = inspect(db.engine)
|
|||
|
|
tables = inspector.get_table_names()
|
|||
|
|
if 'favorites' in tables:
|
|||
|
|
print("✅ 验证成功:favorites表已存在")
|
|||
|
|
else:
|
|||
|
|
print("❌ 验证失败:favorites表不存在")
|
|||
|
|
|
|||
|
|
except Exception as e:
|
|||
|
|
print(f"❌ 创建收藏表失败:{str(e)}")
|
|||
|
|
|
|||
|
|
if __name__ == '__main__':
|
|||
|
|
create_favorites_table()
|