Home python inserting with AutoIncRement Error: SQLite3.0perationalerror: Table Ranobes HAS 2 Columns But 1...

inserting with AutoIncRement Error: SQLite3.0perationalerror: Table Ranobes HAS 2 Columns But 1 Values ​​Were Supplied

Author

Date

Category

created database via SQLiteStudio (3.2.1).

Create Table Ranobes (
  Ranobe_ID Integer Primary Key AutoIncrement,
  Name String (256)
);

Decided to add an entry. I read that if the field is worth AutoIncrement , then the ID write is not necessary, in itself will be added. Just do not need Values ​​register Ranobe_id .

def_new_ranobe (Self, Name):
  With self.connection:
    return self.cursor.execute ("INSERT INTO RANOBES VALUES (?)", (Name,))

Well, caused this business:

db.add_new_ranobe (book1 ')

but got such a mistake:

return self.cursor.execute ("INSERT INTO RANOBES VALUES (?)", (Name,))
SQLite3.0perationalerror: Table Ranobes Has 2 Columns But 1 Values ​​Were Supplied

Then added to Values ​​New value, id , and in hand, it was prescribed, now the recording was added, but without taking into account AutoIncrement .

What’s wrong?


Answer 1, Authority 100%

In the general case in the SQL team:

insert into table_name (col_name_1, col_name_2, col_name_5)
Values ​​(Value_For_Col_2, Value_For_col_5)

You can specify which columns We want to write data (Please note the list of columns in brackets after the table name ). If you do not specify a list of columns after the table name, it is understood that we insert the data into all columns of the table . Accordingly, passing only one value – we have a mismatch – 2 columns in the table and only one value is transmitted to Values ​​(...) .

In your case, you can explicitly specify the list of columns:

insert into ranobes (name) Values ​​(?)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions