Skip to content
Advertisement

sqlite3.OperationalError python

so what i’am basically trying to do is getting data from a from developed with pyqt and insert it into a database, the problem is with my ID column,this is the code i’am using to insert the data to the database :

connection.execute("INSERT INTO UTILISATEURS VALUES (?,?,?,?,?,?) ",(fullname,email,cin,address,phonenumber,ribnumber))

i always get this error :

sqlite3.OperationalError: table UTILISATEURS has 7 columns but 6 values were supplied

when i enter a query to insert into the table directly from sqlite cli i get the results desired without needing to insert the ID it automatically autoincrements

here is the output of the .schema command :

sqlite> .schema
CREATE TABLE ADMINSS(USERNAME TEXT NOT NULL,PASSWORD TEXT);
CREATE TABLE UTILISATEURS(ID INTEGER PRIMARY KEY,FULLNAME TEXT NOT NULL,EMAIL INT NOT NULL,CIN INTEGER,ADDRESS CHAR(50),PHONE INTEGER,RIB INTEGER);

Advertisement

Answer

You need to pass a list of columns:

connection.execute("INSERT INTO UTILISATEURS (FULLNAME, EMAIL, CIN, ADDRESS, PHONE, RIB) VALUES (?,?,?,?,?,?) ", (fullname, email, cin, address, phonenumber, ribnumber))

The only way to skip the list is to pass all 7 columns.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement