如何仅将一个值作为变量插入到 sqlite3 table 中,同时将 null 插入到其他列

How to insert only one value into sqlite3 table as an variable while inserting null to every else column

我想修改下面的代码,以便我只将 input 变量插入 table。所有其他列应存储 NULL 值。我认为最明显的解决方案是声明 column2 = NULLcolumn3 = NULL,但我在想还有其他方法吗?

import sqlite3

column1 = input()

sqliteConnection = sqlite3.connect('database.db')
cursor = sqliteConnection.cursor()

sqlite_insert_with_param = "INSERT INTO ideas (column1, column2, column3) VALUES (?, ?, ?);" #column1 is primary key

data_tuple = (column1, column2, column3)
cursor.execute(sqlite_insert_with_param, data_tuple)
sqliteConnection.commit()

cursor.close()

最终我希望它在 Tkinter 应用程序中工作,提示用户使用 Entry-widget 输入第 1 列,它会创建数据库条目,除了主键之外没有任何其他信息。

如果您从列表中删除其他列,例如:

sqlite_insert_with_param = "INSERT INTO ideas (column1) VALUES (?);"
data_tuple = (column1,)
cursor.execute(sqlite_insert_with_param, data_tuple)
sqliteConnection.commit()

那么 column2column3 将在新插入的行中 null,除非您在 table 的定义中为它们定义了默认值。