Files
aitsc/create_favorites_table.py
2025-08-29 00:34:40 +08:00

32 lines
949 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- 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()