import pymysql as sql

conn = sql.connect(
    host='localhost',
    user='root',
    password='20240108',
    database='usr'
)
table = 'tc2'
cur = conn.cursor()
try:
    cur.execute(f"SHOW COLUMNS FROM {table}")
    columns = cur.fetchall()
    print(columns)
    cols = [cl[0] for cl in columns]
    print(cols)
    for sr in cols:
        sq = f'ALTER TABLE {table} MODIFY COLUMN ' + sr + ' TEXT;'
        try:
            cur.execute(sq)
        except sql.IntegrityError:
            print(sq+'has an error')
except sql.OperationalError:
    print(sql.OperationalError)

 

posted on 2024-04-08 18:39  XiSoil  阅读(41)  评论(0编辑  收藏  举报