简体   繁体   中英

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);

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.

okay i accepted the previous answer but with a slight modification :

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

this worked for turns out i should parse to string the values i got from my text box in the form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM