| 1234567891011121314151617181920212223242526272829303132333435 |
- import pymysql
- DB_CONFIG = {
- "host": "rm-f8ze60yirdj8786u2.mysql.rds.aliyuncs.com",
- "port": 3306,
- "user": "root",
- "password": "csqz@20255",
- "db": "csqz-client",
- "charset": "utf8mb4",
- "cursorclass": pymysql.cursors.DictCursor
- }
- def migrate():
- conn = pymysql.connect(**DB_CONFIG)
- try:
- with conn.cursor() as cursor:
- print("Checking family_relation_info schema...")
- cursor.execute("DESCRIBE family_relation_info")
- columns = [col['Field'] for col in cursor.fetchall()]
-
- if 'sub_relation_type' not in columns:
- print("Adding 'sub_relation_type' column...")
- cursor.execute("ALTER TABLE family_relation_info ADD COLUMN sub_relation_type INT DEFAULT 0 COMMENT '子关系类型'")
- print("Column added.")
- else:
- print("'sub_relation_type' column already exists.")
-
- conn.commit()
- except Exception as e:
- print(f"Migration failed: {e}")
- finally:
- conn.close()
- if __name__ == "__main__":
- migrate()
|