45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
|
|
import pymysql
|
||
|
|
|
||
|
|
# 数据库连接信息
|
||
|
|
host = 'localhost'
|
||
|
|
user = 'root'
|
||
|
|
password = 'taiyi1224'
|
||
|
|
database = 'kamaxitong'
|
||
|
|
|
||
|
|
try:
|
||
|
|
# 连接数据库
|
||
|
|
connection = pymysql.connect(
|
||
|
|
host=host,
|
||
|
|
user=user,
|
||
|
|
password=password,
|
||
|
|
database=database,
|
||
|
|
charset='utf8mb4'
|
||
|
|
)
|
||
|
|
|
||
|
|
with connection.cursor() as cursor:
|
||
|
|
# 检查device表结构
|
||
|
|
cursor.execute("DESCRIBE device")
|
||
|
|
device_columns = cursor.fetchall()
|
||
|
|
print("Device table columns:")
|
||
|
|
for col in device_columns:
|
||
|
|
print(f" {col[0]} ({col[1]})")
|
||
|
|
|
||
|
|
# 检查是否有ip_address字段
|
||
|
|
has_ip_address = any(col[0] == 'ip_address' for col in device_columns)
|
||
|
|
print(f"\nDevice table has ip_address column: {has_ip_address}")
|
||
|
|
|
||
|
|
# 检查alembic_version表
|
||
|
|
cursor.execute("SHOW TABLES LIKE 'alembic_version'")
|
||
|
|
result = cursor.fetchone()
|
||
|
|
if result:
|
||
|
|
cursor.execute("SELECT * FROM alembic_version")
|
||
|
|
version_result = cursor.fetchone()
|
||
|
|
print(f"\nAlembic version: {version_result}")
|
||
|
|
else:
|
||
|
|
print("\nAlembic version table does not exist")
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Error connecting to MySQL: {e}")
|
||
|
|
finally:
|
||
|
|
if 'connection' in locals():
|
||
|
|
connection.close()
|