Answer the question
In order to leave comments, you need to log in
Error: sqlite3.OperationalError: no such column how to fix?
The code:
import sqlite3
connect = sqlite3.connect("lun_db.db")
cursor = connect.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS lun_db(
user_id INTEGER,
ochki INTEGER,
user_name TEXT
)
""")
connect.commit()
userid = 111
username = "ppppp"
cursor.execute(f"SELECT user_id FROM lun_db WHERE user_id = '{userid}'")
if cursor.fetchone() is None:
cursor.execute("INSERT INTO lun_db VALUES(?, ?, ?);", (userid, username ,0))
connect.commit()
cursor.execute(f'UPDATE lun_db SET user_name = {username} WHERE user_id = "{userid}"')
connect.commit()
File "C:\lun_bot\test_ckay_aiogram.py", line 157, in echo_message
cursor.execute(f'UPDATE lun_db SET user_name = {username} WHERE user_id = "{userid}"')
sqlite3.OperationalError: no such column: star
Answer the question
In order to leave comments, you need to log in
It turns out this is because your "username" in Insert is not wrapped in quotes, and adding a user is also not correct in your table "INTEGER, INTEGER, TEXT", and you enter it as "INTEGER, TEXT, INTEGER" Here is the code:
cursor.execute(f"SELECT user_id FROM lun_db WHERE user_id = '{userid}'")
if cursor.fetchone() is None:
cursor.execute("INSERT INTO lun_db VALUES(?, ?, ?);", (userid, 0, f"{username}"))
connect.commit()
cursor.execute('UPDATE lun_db SET user_name = ? WHERE user_id = ?', (f"{username}", userid))
The user_name column is there, but it doesn't work
cursor.execute('UPDATE lun_db SET user_name = ? WHERE user_id = ?', (username, userid))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question