How can I insert NULL data into MySQL database with Python?

后端 未结 4 1746
北荒
北荒 2020-12-03 00:16

I\'m getting a weird error when inserting some data from a Python script to MySQL. It\'s basically related to a variable being blank that I am inserting. I take it that MyS

4条回答
  •  天命终不由人
    2020-12-03 01:15

    When using mysqldb and cursor.execute(), pass the value None, not "NULL":

    value = None
    cursor.execute("INSERT INTO table (`column1`) VALUES (%s)", (value,))
    

    Found the answer here

提交回复
热议问题