import pymysql DB_CONFIG = { "host": "rm-f8ze60yirdj8786u2wo.mysql.rds.aliyuncs.com", "port": 3306, "user": "csqz", "password": "csqz@2026", "db": "csqz-client", "charset": "utf8mb4", "cursorclass": pymysql.cursors.DictCursor } def update_db(): conn = pymysql.connect(**DB_CONFIG) try: with conn.cursor() as cursor: # Check if file_type column exists cursor.execute("SHOW COLUMNS FROM genealogy_records LIKE 'file_type'") if not cursor.fetchone(): cursor.execute("ALTER TABLE genealogy_records ADD COLUMN file_type VARCHAR(50) DEFAULT '图片'") print("Added file_type") else: print("file_type already exists") conn.commit() except Exception as e: print(f"Error: {e}") finally: conn.close() if __name__ == '__main__': update_db()