【问题标题】:Saving value in python to mysql db将python中的值保存到mysql db
【发布时间】:2018-11-23 19:52:28
【问题描述】:

大家好,我在尝试将值保存到 mysql 数据库时遇到错误。这是我的代码。

db = MySQLdb.connect(host="localhost", user="root", passwd="developer", db="recaptcha")

cur.execute("SELECT * FROM `captcha_response`")

cur.execute("INSERT into captcha_response(id, response) values (%s, %s)" % (0, token))

这是我的错误。

raise errorclass, errorvalue
OperationalError: (1054, "Unknown column '03ACgFB9t_ZvEFuHACU8HebuQ6zrFe_k0n9SLsoJU5GC3tm' in 'field list'")

这里是 mysql 数据库信息。

    my database name is: "recaptcha"
    my table name is: "captcha_response"
    Example of where the items get stored
                          id                           response

Edit Copy Delete          1                            03ACgFB9uxJ...                                       

Here is the image of my table

【问题讨论】:

  • captcha_response 表有哪些列?您可能还需要在表名和 (id,response) 的括号之间留一个空格。
  • 列是id和response
  • id 基本上是一个随着我不断添加响应而不断上升的数字
  • 你不应该自己增加 ID,你应该能够使用 MySQL 中的 Auto Increment 功能或列的 AI 复选框。然后你不要只插入 ID 到响应中,然后 SQL 会为你处理 ID 列。
  • 所以只需插入响应即可

标签: python mysql database


【解决方案1】:

这就是答案,伙计们!感谢大家的帮助!

db = MySQLdb.connect(host="localhost", user="root", passwd="developer", db="recaptcha")

cur.execute("SELECT * FROM `captcha_response`")

cur.execute("INSERT into captcha_response(id, response) values (%s, %s)", (0, token))

db.commit()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-23
    • 2013-08-28
    • 1970-01-01
    相关资源
    最近更新 更多