【发布时间】:2021-09-04 04:51:22
【问题描述】:
我的表及其主键上有一个 id 并设置为自动增量
def register():
if (t1.get()=="" or t2.get()=="" or t3.get()==""):
messagebox.showinfo("Result","Please Complete the Provided Details!")
else:
databases = mysql.connector.connect(
host ="localhost",
user = "userdata",
password = "",
database = "facerecog"
)
cursors = databases.cursor()
cursors.execute("SELECT * from record")
result = cursors.fetchall()
这是我的 ID 设置
id = 2 #This is the ID That I set
对于结果中的 x:
id ++1 #auto increment from my python
sql = "INSERT INTO record(ids,names,course_year,positions) values(%s, %s ,%s , %s)"
val = (id, t1.get(), t2.get(), t3.get())
cursors.execute(sql,val)
databases.commit()
我得到的错误
mysql.connector.errors.IntegrityError: 1062 (23000): Duplicate entry '3' for key 'PRIMARY'
如何自动递增?
【问题讨论】:
标签: python localhost mysql-connector