baoxiang/backend/check_db.py

27 lines
674 B
Python
Raw Normal View History

2025-12-16 18:06:50 +08:00
"""
检查数据库表结构
"""
import sys
import os
# 添加项目根目录到 Python 路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from app.core.database import engine
from sqlalchemy import text
with engine.connect() as conn:
# 显示所有表
result = conn.execute(text('SHOW TABLES'))
tables = [row[0] for row in result]
print("Tables in database:")
for table in tables:
print(f" - {table}")
# 检查users表结构
if 'users' in tables:
print("\nUsers table structure:")
result = conn.execute(text('DESCRIBE users'))
for row in result:
print(f" {row[0]}: {row[1]}")