def fillblast(sequentie, titel_lijst, score_lijst, e_lijst, iden_lijst, pos_lijst, gaps_lijst):
conn = mysql.connector.connect(host = "ithurtswhenip.nl", user = "pg2", password = "pg2", database= "pg2", port= "3307")
cursor = conn.cursor()
Blast = 1000
for i in range(0,len(titel_lijst)):
Blast =+ 2
cursor.execute("INSERT INTO `pg2`.`Blast` (`Blast_id`, `Blast_seq`, `Blast_titel`, `Blast_score`, `Blast_E`, `Blast_gaps`, `Blast_pos`, `Blast_iden`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s);", (Blast, sequentie[i] ,titel_lijst[i], score_lijst[i], e_lijst[i], iden_lijst[i], pos_lijst[i], gaps_lijst[i]))
print("1 record toegevoegd")
cursor.commit()
cursor.close()
conn.close()
我得到以下错误:
AttributeError: 'MySQLCursor' object has no attribute 'commit'
它是怎么来的,哪里出了问题? 我试着和MySQLWorkbench联系。
编辑:
现在我得到以下错误:
mysql.connector.errors.DatabaseError: 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
在修复一些遗留代码时(这显然已经几年没用了,所以用户不再尝试使用它),我们遇到了同样的错误,在Django中使用MySQL python包。但是,使用此答案和其他答案的建议会导致不同的错误,因为它发生在Django ORM中:
因此,对于那些在使用conn.commit()而不是cursor.commit()之后遇到此错误的用户,您可以使用
enter_transaction_management
和leave_transaction_management
(请注意,这是针对Django 1.4.6和MySQL python 1.2.5的;在完成Django升级之后,我可能必须更新此选项):因为你不能提交光标!您必须提交连接。
Check the docs。。。
相关问题 更多 >
编程相关推荐