Python Forum
How to handle None with mysql.connector
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to handle None with mysql.connector
#1
Hello everyone, Can anyone advice how to handle empty string or None when insert data in mysql integer column.
Here is the code i have:

import mysql.connector
cnx = mysql.connector.connect(user='user',
                                  password='pass',
                                  host='192.168.18.1',
                                  database='db')
data = None
conn = cnx.cursor()
conn.execute("insert into contract(red) values('{}')".format(data))
cnx.commit()
and here is the otput :
mysql.connector.errors.DataError: 1366 (22007): Incorrect integer value: 'None' for column 'red' at row 1
Problem is that i don't know when the data would be integer or None.
Reply


Messages In This Thread
How to handle None with mysql.connector - by verb - Nov-16-2018, 07:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 708 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,168 Feb-09-2022, 09:55 AM
Last Post: ibreeden
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 6,727 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,659 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  Program stuck at mysql.connector.connect zazas321 1 2,095 Jul-29-2021, 10:49 AM
Last Post: zazas321
  MYSQL.CONNECTOR ERROR DB1 8 3,890 Jul-23-2021, 03:31 AM
Last Post: DB1
  mysql.connector Nobima 1 1,912 Apr-10-2020, 12:00 PM
Last Post: Larz60+
  Trouble retrieving dictionary from mysql.connector cursor swechsler 2 3,077 Sep-17-2019, 05:21 PM
Last Post: swechsler
  Using VBA to Call a Python script causes error in pyodbc connector pcarra 1 2,852 Jun-11-2019, 04:14 PM
Last Post: pcarra
  Add a stored procedure with variable using MySQL Connector UtiliseIT 0 2,302 May-04-2019, 12:46 PM
Last Post: UtiliseIT

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020