What does 'Truncated incorrect DOUBLE value' error mean in MySQL Connector with Python and how do I fix it?

44 views Asked by At

First ERROR message:

mysql.connector.errors.DataError: 1292 (22007): Truncated incorrect DOUBLE value:

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

I have tried several times to find a solution online and have seen other users who have had the same problem.

Unfortunately, it hasn't solved my problem yet. I've Googled to find a solution similar to my problem and that hasn't helped either.

Okay, the problem is that I keep getting errors from pycharm which are as follows

mysql.connector.errors.DataError: 1292 (22007): Truncated incorrect DOUBLE value:

What does this mean specifically?

Is there something wrong with my database?

What is it?

Here is my table that I have 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`)
);

And I want to update a user with python.

The coding is as follows:

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.

  • Have seen other solutions on Stackoverflow that are similar to my problem.

    Have Googled my way with the Error coding.

    Changed my table on mysql.

1

There are 1 answers

0
nacho On

You have 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 have your value in first position, so you need to change it. Also I removed some brackets not needed and some comma