0
votes

Getting error:

"insert cur.execute("INSERT INTO book VALUES (NULL,?,?,?,?)" ,(title,author,year,isbn)) sqlite3.OperationalError: table book has 4 columns but 5 values were supplied"

while running below code, i want to id column with primary key integer while inserting data in table in database.

import sqlite3

def connect():
    conn=sqlite3.connect("books.db")
    cur=conn.cursor()
    cur.execute("CREATE TABLE IF NOT EXISTS book (id INTEGER PRIMARY KEY, title text, author text, year integer, isbn integer)")
    conn.commit()
    conn.close()

def insert(title,author,year,isbn):
    conn=sqlite3.connect("books.db")
    cur=conn.cursor()
    cur.execute("INSERT INTO book VALUES (NULL,?,?,?,?)" ,(title,author,year,isbn))
    conn.commit()
    conn.close()

Please help.

1

1 Answers

0
votes

why you put NULL in book VALUES (NULL,?,?,?,?) ? try without NULL

cur.execute("INSERT INTO book VALUES (?,?,?,?)" ,(title,author,year,isbn))