我想在mysql数据库中插入一些条目。在
当我在python脚本中这样做时,我得到了:
Error 1062: Duplicate entry '222' for key 'product_code'. product_code is an unique field.
当我在mysql命令行中执行此操作时,我得到:
Error 1205(HY000):Lock wait timeout exceed; try restarting transaction.
Mysql安装在win32上,表的引擎是innodb。在
代码:
conn = mdb.connect(user = 'root', passwd = '[REMOVED]', db = 'vancl')
cur = conn.cursor()
sql2 = "insert into vancl.vancl_query1(product_code) values('100000')"
print sql2
cur.execute(sql2)
cur.close()
这意味着
product_code
列上有一个唯一的索引约束。unique index约束告诉MySQL一个字段不能有重复的值,即每个字段必须唯一。当222值已经存在于列的某个位置时,尝试将值222插入到产品代码中时,会出现一个“重复项”错误。在如果使用像InnoDB这样的事务引擎,则不会保存数据,因为MySqlDb默认为auto commit off。要将数据实际保存到数据库,必须调用commit
相关问题 更多 >
编程相关推荐