2012-04-13 107 views
1

我在MySQLdb中使用xampp和python。我連接,然後運行:爲什麼MySQL遞增自動增量,但不插入行?

cursor.execute("INSERT INTO customer SET name='aaa'") 

沒有錯誤引發,但沒有行已被添加到數據庫中(如pypmyadmin選中)。但是,表遞增其自動增量字段。

這是怎麼回事,我該如何阻止它?

+0

也許這將有助於http://stackoverflow.com/questions/5342698/cursor-executeinsert-into-im-entry-test-entrym-values-p – 2012-04-13 15:03:13

回答

5

正如@Chasing Death所指出的那樣。正確的語法是

cursor.execute("INSERT INTO customer(name) VALUES('aaa')") 

您還必須提交事務才能將數據實際存儲在數據庫中。

connection.commit()