相关疑难解决方法(0)

不要使用已删除的主键

插入ID 1和2。删除ID2。插入新行,它的ID为2,而不是3。我该如何更改?我不想重用主键。

import sqlite3, os

os.remove('mydatabase.db')
conn = sqlite3.connect("mydatabase.db") # or use :memory: to put it in RAM
cursor = conn.cursor()

# create a table
cursor.execute("CREATE TABLE if not exists albums (id INTEGER PRIMARY KEY NOT NULL, title text, artist text, release_date text, publisher text, media_type text)")
cursor.execute("CREATE TABLE if not exists anti (id INTEGER, title text, artist text, release_date text, publisher text, media_type text)")
conn.commit()

cursor.execute("INSERT INTO albums VALUES (null, 'Glow', 'Andy Hunter', '7/24/2012', 'Xplore Records', 'MP3')")
cursor.execute("INSERT INTO …
Run Code Online (Sandbox Code Playgroud)

python sqlite primary-key

2
推荐指数
1
解决办法
143
查看次数

标签 统计

primary-key ×1

python ×1

sqlite ×1