简体   繁体   English

如何检查为什么我的INSERT查询不起作用?

[英]How do I check why my INSERT query is not working?

conn = MySQLdb.connect(host=IP,user='john',passwd='ab2nng',db='mydb')
cursor = conn.cursor()

#this works.
cursor.execute("select * from crawl_log")
res = cursor.fetchall()
print res

#this doesn't work.
cursor.execute("insert into crawl_log(k, v) values(%s, %s)", ('test','test'))

How do I know why it didn't work? 我怎么知道为什么它不起作用? No errors print, nothing. 没有错误打印,什么也没有。

The typical cause of an issue like this is a misspelling of the row/table/database name 这样的问题的典型原因是行/表/数据库名称的拼写错误

please double check, this is always the main issue with me messing up 请仔细检查,这始终是我搞砸的主要问题

ANOTHER thing is that the row/table/db name might be TOO SHORT, to fix this add '' around the name for example, key would be 'key' 另一件事是,行/表/数据库名称可能太短了,例如,要在名称周围解决此添加'',键将是'key'

hopefully this will fix your issue 希望这可以解决您的问题

By default it will start a transaction which will need to be committed after any statement that affects change to the data. 默认情况下,它将启动一个事务,该事务需要在影响数据更改的任何语句之后提交。 Have you tried conn.commit() after your insert? 插入后是否尝试过conn.commit()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用此 if 语句检查我的日期? - How do I check my dates with this if statement? 运行 Cerebro 后,我在 backtrader 中的投资组合价值没有发生任何变化,我如何检查它是否正常工作 - After running Cerebro nothing is happening to my portfolio value in backtrader, how do i check if it is working or not 为什么我的查询变成布尔值,如何防止这种情况发生,所以我可以对其进行迭代? - Why is my query turning into a boolean and how do I prevent this, so I can iterate over it? 如何使用Python中的MySQLdb检查插入是否成功? - How do I check if an insert was successful with MySQLdb in Python? 如何将变量的值插入 MySQL 数据库? - How do I insert the value of my variable into my MySQL database? 为什么我的SQL查询不起作用? - Why is my SQL query not working? 如何检查我的 sqlite 列是否不在我的数据框中? - How do i check if my sqlite column is not in my dataframe? 如何在MySQL Python中进行upsert(更新和插入)查询? - How can I do upsert (update and insert) query in MySQL Python? 如何在raw_input查询中插入变量? - How do I insert a variable into a raw_input query? 如何在 Tkinter 中的 output 小部件中插入垂直滚动条? - How do I insert a vertical scrollbar to my output widget in Tkinter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM