0

Im trying to insert values into a table.

eg:

cursor = cnx.cursor()
query = "INSERT INTO info( id, Diet ) VALUES( %s, %s)"
values = [
    (1, ??? ),
    (2, "Low carb diet"),
    (3, "nut allergy"),

Item 1 currently has no information but this could change in the future.

I have tried using "NULL" - this doesn't create a null value it is a string (beginner mistakes :/)

Trying to insert null without quotations classes as an unresolved reference.

Leaving the field empty produces the following

line 329, in _batch_insert
"Failed executing the operation; %s" % err)
mysql.connector.errors.InterfaceError: Failed executing the operation; Could not process parameters

i could insert data one at a time, but id like to know if there was an alternative?

null.ts
  • 33
  • 1
  • 6
  • Use the corresponding Python value, [`None`](https://stackoverflow.com/questions/19473185/what-is-a-none-value). – Amadan Mar 26 '20 at 07:21

1 Answers1

0

Change your code

values = [
    (1, None ),
    (2, "Low carb diet"),
    (3, "nut allergy"),
olegsv
  • 1,422
  • 1
  • 14
  • 21