[英]pymysql.err.IntegrityError: (1048, “Column 'dob' cannot be null”)
[英]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")
錯誤。
我嘗試將titre
和descr
放在 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 應該是 tuple、list 或 dict afaik。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.