首页 > 解决方案 > sqlite 有没有办法在列中插入新值时插入精确值作为主键或其他默认值?

问题描述

我相信必须首先创建该行以获得自增PK。然后我可以用生成的 PK 值替换一列。但我没有得到正确的结果。

insert = "insert into table(name, status) values (:Name, :Status)
params = {'Name': Jack,
          'status' : active
         }
db.execute(insert, params)
db.commit()
insert_type = "replace into table (type) values (select id from table)"
db.execute(insert_type)
db.commit()

所以表确实有列作为 id(自动增量)、名称、状态和类型(默认 0 或 id)将主键列值插入同一个表中的非主键列。

标签: pythonsqlite

解决方案


我认为您可以使用 DEFUALT = blank 为任何列创建默认值。


推荐阅读