命令不同步;您可以立即运行此命令,同时尝试通过某种条件从表中删除行
我试图根据某个条件从数据库中的表中删除行(在这种情况下为特定日期) 此查询在MySQL Workbench中没有任何问题,但是通过Python,我得到了此错误: “命令不同步;您现在无法运行此命令”
def delete_from_available_donations (self):
self.cursor.execute("SET SQL_SAFE_UPDATES = 0;\
DELETE FROM available_donations WHERE expiry_date = '2022-05-27'")
res = self.connection.commit()
return 1
def main():
q = DataQueries("root", "amitbrilant" , "Blood_bank")
q.delete_from_available_donations()
I'm trying to delete rows from a table in the database according to a certain condition (in this case by a specific date)
This query works without any problem in MySQL workbench, but through Python, I get this error:
"Commands out of sync; you can not run this command now"
def delete_from_available_donations (self):
self.cursor.execute("SET SQL_SAFE_UPDATES = 0;\
DELETE FROM available_donations WHERE expiry_date = '2022-05-27'")
res = self.connection.commit()
return 1
def main():
q = DataQueries("root", "amitbrilant" , "Blood_bank")
q.delete_from_available_donations()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如已经讨论的在这里当您搜索错误消息时,您必须先在提交之前先从光标取得结果。
这也意味着您必须将语句分为单个执行,以便能够在每个语句之后释放光标。
根据我的经验,可以拆分语句并捕获结果生成器(
fetchall
不需要)这是
mysql-connector
和pymysql
>。老实说,我不知道为什么...As already discussed here when you search your error message, you have to fetch results from the cursor first before you commit.
This also means that you have to split your statements into single executes to be able to free the cursor after each statement.
From my experience it is sufficient to split the statements and catch the result generator (
fetchall
is not necessary)This is diffrent for
mysql-connector
andpymysql
. To be honest I don't know why...