How fix "pymysql.err.IntegrityError: (1048, "Column 'ProTitre' cannot be null")" error in python?

How fix "pymysql.err.IntegrityError: (1048, "Column 'ProTitre' cannot be null")" error in python?

我是 Python 中的 sql 新手。我有一些数据要发送到我的 SQL 数据库。但是我有一个 pymysql.err.IntegrityError: (1048, "Column 'ProTitre' cannot be null") 错误。

我尝试将 titredescr 放在 var data[] 上,然后将 data[] 放在 cursor.execute(sql, data).

并直接输入sql = ("INSERT INTO projet (ProTitre, ProDescription) VALUES (%s, %s)", (self.sqlEntryTitreProjet, self.sqlEntryDescrProjet))cursor.execute(sql, self.sqlEntryTitreProjet, self.sqlEntryDescrProjet).

def exemple(self):
    self.sqlEntryTitreProjet = "test1"
    self.sqlEntryDesrcrProjet = "test descr"

def myConnectin(self):
    self.connection = pymysql.connect(host='127.0.0.1',
                                 user='root',
                                 password='',
                                 db='bd_outiltesting',
                                 charset='utf8mb4',
                                 cursorclass=pymysql.cursors.DictCursor)


def addItemProjet(self):
    self.myConnection()
    titre = self.sqlEntryTitreProjet
    descr = self.sqlEntryDesrcrProjet
    sql = ("INSERT INTO projet (ProTitre, ProDescription) VALUES (%s, 
    %s)", (titre, descr))
    cursor = self.connection.cursor()
    cursor.execute(sql)
    self.connection.commit()
    print("cursor.description:", cursor.description)
    cursor.close()
    if self.connection.is_connected():
        self.connection.close()
        print("MySQL connection is closed")

pymysql.err.IntegrityError: (1048, "Column 'ProTitre' cannot be null")

尝试:

sql = "INSERT INTO projet (ProTitre, ProDescription) VALUES (%s, %s)"
cursor = self.connection.cursor()
cursor.execute(sql, (titre, descr))

args 应该是元组、列表或字典 afaik。