Kamixitong/check_db.py
2025-11-11 21:39:12 +08:00

50 lines
1.5 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
检查数据库表结构
"""
import sys
import os
# 添加项目路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from app import create_app, db
from sqlalchemy import text
def check_database_structure():
"""检查数据库表结构"""
app = create_app()
with app.app_context():
try:
# 检查license表结构
result = db.session.execute(text("PRAGMA table_info(license)"))
columns = result.fetchall()
print("=== License表结构 ===")
for column in columns:
print(f"列名: {column[1]}, 类型: {column[2]}, 是否可为空: {column[3]}, 默认值: {column[4]}, 是否为主键: {column[5]}")
# 查找license_key列
license_key_column = None
for column in columns:
if column[1] == 'license_key':
license_key_column = column
break
if license_key_column:
print(f"\nlicense_key列信息:")
print(f" 类型: {license_key_column[2]}")
print(f" 是否可为空: {license_key_column[3]}")
else:
print("\n未找到license_key列!")
except Exception as e:
print(f"检查数据库结构时出错: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
check_database_structure()