Corrected title: Explaining the "Truncated incorrect DOUBLE value" error in MySQL Connector with Python and providing ways to fix it
P粉021708275
P粉021708275 2023-09-12 14:51:28
0
1
624

First error message:

mysql.connector.errors.DataError: 1292 (22007): 截断错误的DOUBLE值:

\----------------------------------------------------------------------------------------------

I have tried many times to find a solution online and have seen other users encounter the same problem.

Unfortunately, this hasn't solved my problem. I've found a similar solution to my problem by googling, but that didn't help either.

Well, the problem is that I keep getting the following error from pycharm:

mysql.connector.errors.DataError: 1292 (22007): 截断错误的DOUBLE值:

What exactly does this mean?

Is there something wrong with my database?

what is the problem?

This is the table I created:

CREATE TABLE `employee` (
    `emp_id` INTEGER NOT NULL,
    `emp_name` VARCHAR (17) NOT NULL,
    `emp_last_name` VARCHAR (17) NOT NULL,
    `emp_email` VARCHAR (17) NOT NULL,
    `emp_status` VARCHAR (17) NOT NULL,
    PRIMARY KEY (`emp_id`)
);

I want to update a user using Python.

code show as below:

def update function(emp_id, emp_name, emp_last_name, emp_email, emp_status):
    emp_data = mysqlconn.cursor()
    sql_update_query = ("UPDATE employee set emp_name = %s, emp_last_name = %s, emp_email = %s, emp_status = %s WHERE emp_id = %s")
    updated_data = (emp_id, emp_name, emp_last_name, emp_email, emp_status)
    emp_data.execute(sql_update_query,updated_data,)
    mysqlconn.commit()
    print("Data Updated")

I don't see any syntax errors.

  • See other solutions to similar problems on Stackoverflow.

    Did a Google search with the wrong encoding.

    Changed my table on mysql.

P粉021708275
P粉021708275

reply all(1)
P粉674757114

You have the wrong order in your data:

def update function(emp_id, emp_name, emp_last_name, emp_email, emp_status):
    emp_data = mysqlconn.cursor()
    sql_update_query = "UPDATE employee set emp_name = %s, emp_last_name = %s, emp_email = %s, emp_status = %s WHERE emp_id = %s"
    updated_data = ( emp_name, emp_last_name, emp_email, emp_status, emp_id)
    emp_data.execute(sql_update_query,updated_data)
    mysqlconn.commit()
    print("Data Updated")
The placeholder for

emp_id is the last one, but you put the value in the first position, so you need to change that. Additionally, I removed some unnecessary parentheses and commas.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template