T
T
Turkmen Time2020-08-23 11:35:49
Python
Turkmen Time, 2020-08-23 11:35:49

Error table X has Y columns but Z values ​​were supplied. How to fix?

import sqlite3

db = sqlite3.connect('Account.db')
sql = db.cursor()

sql.execute("""CREATE TABLE IF NOT EXISTS oooaaa (
    id INT PRIMARY KEY,
    mukaka TEXT
)""")

mukaka = '123'

sql.execute(f"SELECT mukaka FROM oooaaa WHERE mukaka = '{mukaka}'")
if sql.fetchone() is None:
    sql.execute(f"INSERT INTO oooaaa VALUES (?)",(mukaka))
    db.commit()
    print('Мукака добавлен')
else:
    print("Такой мукака уже имеется")

It gives an error
sql.execute(f"INSERT INTO oooaaa VALUES (?)",(mukaka))
sqlite3.OperationalError: table oooaaa has 2 columns but 1 values ​​were supplied

I want to make the id itself increase each time

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-08-23
@MrSel

Your table has 2 columns. That is, you need to pass 2 parameters, and you pass 1.
You can do this:

sql.execute(f"INSERT INTO oooaaa VALUES (?,?)",('тут любой id',mukaka))

PS: id - it is customary to call a unique value.

D
Dr. Bacon, 2020-08-23
@bacon

and insert id (or specify as another argument, or specify only one mukaka field after the table name) and know the difference (mukaka)vs(mukaka, )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question