MySQL python 连接器代码无误中止(来自 MySQL 文档的代码)

MySQL python connector code aborts without error (Code from the MySQL documentation)

我试图使用 MySQL 文档中给出的 python 连接器代码,并在一个已经创建的小型数据库上对其进行测试,但它失败了。该代码只是应该连接到数据库并添加一个新的电子邮件地址。

import mysql.connector
from mysql.connector import errorcode


cnx = mysql.connector.connect(user='root', password='pwd', host='localhost', database='db')

cursor = cnx.cursor()  

add_email = ("INSERT INTO employee(MID, Email) VALUES (%s,%s)")
email_details = (NULL, "a@a.de")

cursor.execute(add_email, email_details)

cnx.commit()
input("data entered successfully")
cnx.close()

通过设置断点,我发现问题可能出在cursor.execute()语句上。 (我使用 Null 作为第一个 %s 因为 MID 是自动递增 btw)

为了解决这个问题NULL(对于自动递增"MID")需要替换为None