50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import os
|
||
import sys
|
||
|
||
# 添加项目根目录到Python路径
|
||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
|
||
# 在导入应用之前加载环境变量
|
||
try:
|
||
from dotenv import load_dotenv
|
||
if load_dotenv():
|
||
print("成功加载.env文件")
|
||
except ImportError:
|
||
print("python-dotenv未安装,跳过.env文件加载")
|
||
|
||
from app import create_app, db
|
||
|
||
# 创建应用实例
|
||
app = create_app()
|
||
|
||
with app.app_context():
|
||
try:
|
||
# 检查表结构
|
||
from sqlalchemy import inspect
|
||
inspector = inspect(db.engine)
|
||
tables = inspector.get_table_names()
|
||
print(f"Database tables: {tables}")
|
||
|
||
# 检查 admin 表结构
|
||
if 'admin' in tables:
|
||
columns = inspector.get_columns('admin')
|
||
print("\nAdmin table columns:")
|
||
for col in columns:
|
||
print(f" - {col['name']}: {col['type']}")
|
||
|
||
# 检查是否有 is_deleted 字段
|
||
has_is_deleted = any(col['name'] == 'is_deleted' for col in columns)
|
||
print(f"\nHas is_deleted column: {has_is_deleted}")
|
||
else:
|
||
print("Admin table not found")
|
||
|
||
# 检查 audit_log 表
|
||
if 'audit_log' in tables:
|
||
print("\nAudit_log table exists")
|
||
else:
|
||
print("\nAudit_log table not found")
|
||
|
||
except Exception as e:
|
||
print(f"Database inspection failed: {e}")
|
||
import traceback
|
||
traceback.print_exc() |