46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
创建古诗词收藏表
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from src.flask_prompt_master import create_app, db
|
|
from src.flask_prompt_master.models.poetry_favorites import PoetryFavorite
|
|
|
|
def create_poetry_favorites_table():
|
|
"""创建古诗词收藏表"""
|
|
app = create_app()
|
|
|
|
with app.app_context():
|
|
try:
|
|
# 创建表
|
|
db.create_all()
|
|
print("✅ 古诗词收藏表创建成功!")
|
|
|
|
# 检查表是否存在
|
|
from sqlalchemy import inspect
|
|
inspector = inspect(db.engine)
|
|
if 'poetry_favorites' in inspector.get_table_names():
|
|
print("✅ 表 'poetry_favorites' 已存在")
|
|
else:
|
|
print("❌ 表 'poetry_favorites' 创建失败")
|
|
|
|
except Exception as e:
|
|
print(f"❌ 创建表失败: {e}")
|
|
return False
|
|
|
|
return True
|
|
|
|
if __name__ == '__main__':
|
|
print("开始创建古诗词收藏表...")
|
|
success = create_poetry_favorites_table()
|
|
if success:
|
|
print("🎉 古诗词收藏功能数据库初始化完成!")
|
|
else:
|
|
print("💥 数据库初始化失败!")
|
|
sys.exit(1)
|