Home  >  Q&A  >  body text

Corrected title: Explaining the "Truncated incorrect DOUBLE value" error in MySQL Connector with Python and providing ways to fix it

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.

P粉021708275P粉021708275404 days ago555

reply all(1)I'll reply

  • P粉674757114

    P粉6747571142023-09-13 09:51:28

    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.

    reply
    0
  • Cancelreply