A
A
arsfilinov2021-06-09 17:15:12
Python
arsfilinov, 2021-06-09 17:15:12

Parameters are not saved in sqlite3, what should I do?

Parameters are not saved in sqlite3, I'm doing everything right. HELP!

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

sql.execute("""CREATE TABLE IF NOT EXISTS users(
  id INT
  balance BIGINT
  name TEXT)""")

db.commit()
user = vk_session.method("users.get", {"user_ids": id})
name = user[0]['first_name']
sql.execute(f"INSERT INTO users VALUES (?, ?, ?)", (id, 0, name))
db.commit()


error occurs: sqlite3.OperationalError: table users has 1 columns but 3 values ​​were supplied

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2021-06-09
@Zoominger

Recreate database.db.
Something tells me that you have an old structure there, where there is only one column.
And yes, it doesn't hurt to create another column for the PRIMARY KEY.

G
galaxy, 2021-06-09
@galaxy

sql.execute("""CREATE TABLE IF NOT EXISTS users(
  id INT
  balance BIGINT
  name TEXT)""")

This query requires commas:
CREATE TABLE IF NOT EXISTS users(
  id INT,
  balance BIGINT,
  name TEXT)

And so, yes, because of IF NOT EXISTS, it seems that the table with the old structure remains and is not recreated

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question