gpt4 book ai didi

Python MySQLdb : Duplicate entry '2147483647' for key 1

转载 作者:行者123 更新时间:2023-12-01 00:55:20 24 4
gpt4 key购买 nike

当我在 Python 中运行程序时出现此错误。这是我的数据库表:

Field           Type            Collation       Null        Key     Default     
articleCode varchar(25) latin1_swedish_ci NO UNI
dateReceived datetime NULL NO MUL 0000-00-00 00:00:00
s100RSD datetime NULL YES 0000-00-00 00:00:00
remarks longtext latin1_swedish_ci YES

为了简化我的程序的问题,我将在此处隔离程序中出错的部分:

import MySQLdb

def main():
dateReceived = '2011-10-07 01:06:30'
articleCode = 'name'
s100rsd = '2011-10-07 01:06:30'
remark_text = 'This is a remark'
db = MySQLdb.connect('server', 'user', 'passwd', 'table_name', port)
cur = db.cursor()
db_query = cur.execute("INSERT INTO tblS100CurrentListing (articleCode, dateReceived, s100RSD, remarks) VALUES ('articleCode', 'dateReceived', 's100rsd', 'remark_text')")
cur.close()
db.close()

if __name__ == '__main__':
main()

这是我得到的错误:_mysql_exceptions.IntegrityError: (1062, "Duplicate entry '2147483647' for key 1")

感谢您的帮助!

最佳答案

您似乎是在向数据库中插入常量,而不是您的实际值。相反,尝试类似的东西;

db_query = cur.execute("INSERT INTO tblS100CurrentListing " +
"(articleCode, dateReceived, s100RSD, remarks) VALUES (%s, %s, %s, %s)",
(articleCode, dateReceived, s100rsd, remark_text))

关于Python MySQLdb : Duplicate entry '2147483647' for key 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11426416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com