[英]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.