【问题标题】:Why is MySQL incrementing the autoincrement, but not inserting rows?为什么 MySQL 增加自动增量,但不插入行?
【发布时间】:2012-04-25 22:34:09
【问题描述】:

我在 MySQLdb 中使用 xampp 和 python。我正在连接然后运行:

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

没有引发错误,但没有向数据库添加任何行(通过 pypmyadmin 检查)。但是,表正在增加其自动增量字段。

发生了什么,我该如何阻止它?

【问题讨论】:

标签: python mysql phpmyadmin xampp mysql-python


【解决方案1】:

正如@Chasing Death 所说。正确的语法是

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

您还必须提交事务才能将数据实际存储在数据库中。

connection.commit()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    相关资源
    最近更新 更多