【发布时间】:2021-12-20 10:57:28
【问题描述】:
如果我从表中删除一条记录,然后创建一条新记录,它确实会重用已删除记录中的 ID - 在顺序 ID 中留下空白。有人能帮忙吗? 我相信受影响的代码在这里:
def Delete():
#open database
Database()
if not tree.selection():
tkMessageBox.showwarning("Warning","Select data to delete")
else:
result = tkMessageBox.askquestion('Confirm', 'Are you sure you want to delete this record?',
icon="warning")
if result == 'yes':
curItem = tree.focus()
contents = (tree.item(curItem))
selecteditem = contents['values']
tree.delete(curItem)
cursor=conn.execute("DELETE FROM REGISTRATION WHERE RID = %d" % selecteditem[0])
conn.commit()
cursor.close()
conn.close()
这是我的输出 - 请注意删除记录的顺序间隙:
【问题讨论】:
-
这是几乎所有数据库引擎中的预期行为,原因有很多(外键完整性超出了我的想象,还有其他原因)。为什么会困扰你?
-
@Marat - 不是真的,但我认为这是异常行为,因为我使用的另一个没有这样做。如果我删除了记录 1,下一条记录输入将进入该插槽。我是初学者,所以将其归结为缺乏经验。
标签: python sqlite tkinter record delete-row