看板 Python 關於我們 聯絡資訊
想請教一下板上的大大 在寫入資料庫時要如何帶入自動編號的id值 my_list=['A','B','C','D'] c.execute("INSERT INTO my_table VALUES(?)", (my_list)) my_list的元素就是對應到資料庫的欄位 但id值是用自動編號 我以為上面那條sql可以忽略id..但不行 那要怎麼把自動編號的id補到程式碼裡呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.41.46.177 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1509083728.A.051.html
hl4: Create table 的時候就決定了吧 10/27 15:10
uranusjr: 在建 table 的時候就必須要有一個 integer primary key 10/27 15:51
uranusjr: autoincrement 了, 不是 insert 的時候加入 10/27 15:51
uranusjr: http://www.sqlite.org/faq.html#q1 10/27 15:53
rs6000: id是pk鍵&auto 但還是程式還是會出錯 10/27 18:27
rs6000: https://i.imgur.com/kVNoazX.png 10/27 18:33
cutekid: 2樓 u 大有提供解法了: 10/27 19:11
cutekid: insert into profile values(NULL,?,?,?) 10/27 19:12
rs6000: 我已經設id是pk&auto ... 10/27 19:21
cutekid: insert into profile values(NULL,?,?,?),記得加 NULL 10/27 19:28
rs6000: 還我海殤君感謝樓上的大大 10/27 19:57
rs6000: ....推文出錯...lol... 10/27 19:58
rs6000: 感謝啦 :) 10/27 19:58