Python MYSQL:列'的数据被截断;mtf&x27;在第一排

Python MYSQL:列'的数据被截断;mtf&x27;在第一排,python,mysql,Python,Mysql,我将每个字符串转换为一个浮点,并限制了上面for循环的小数位数。以下是for循环前后的数组: def MYSQLADD (code, lon, lat): mydb = mysql.connector.connect( host="localhost", user="user", password="password", database="db&quo

我将每个字符串转换为一个浮点,并限制了上面for循环的小数位数。以下是for循环前后的数组:

def MYSQLADD (code, lon, lat):

    mydb = mysql.connector.connect(
        host="localhost",
        user="user",
        password="password",
        database="db"
    )

    finalres=present(lon,lat)

    print (type (finalres))

    print (finalres)

    for x in range (len (finalres)): #Trying to truncate 

        if len (finalres [x])>6:
            finalres[x]=finalres [x][0:6]
        finalres [x]=float (finalres [x])
        print (type (finalres [x]))

    finalres = finalres.append(1)
    mycursor = mydb.cursor()

    sql = """INSERT INTO 2var001 (mtf, el, atf, pm, wa, 
    mta, b6, b19, b16, p)
        VALUES ('finalres [0]', 'finalres [1]', 'finalres 
        [2]', 'finalres [3]', 'finalres [4]', 'finalres 
        [5]', 'finalres [6]', 'finalres [7]', 'finalres 
        [8]', 'finalres [9]')""";

    mycursor.execute(sql)

    mydb.commit()

    print(mycursor.rowcount, "record inserted.")

MYSQLADD (001, -73, 43)



Error: mysql.connector.errors.DatabaseError: 1265 (01000): Data truncated for 
column 'mtf' at row 1

这些值被限制在较少的小数位数,因此我不确定为什么仍然会出现错误。

检查如何在python sql语句中使用值。值上不需要逗号。下面是一个例子


cursor.execute(“插入表值(%s,%s,%s)”,(var1,var2,var3))

sql=“插入2var001值(%s,%s,%s)”,(最终值[0],最终值[1],最终值[2],最终值[3],最终值[4],最终值[5],最终值[6],最终值[7],最终值[8],最终值[9])TypeError:“非类型”对象不是SubscriptableMTF列的数据类型是什么?mtf是浮点型。在上面的for循环中,我将所有列从string转换为float。表
2var001
中的所有列数据类型都是float?是的,它们都是float。
['-13.3400001525878906', '671', '-7.63600015640258789', 
'125', '4.25199985504150391', '23.1439990997314453', 
'-13.8000001907348633', '314', '357']

[-13.34, 671.0, -7.636, 125.0, 4.2519, 23.143, -13.8, 
314.0, 357.0]