V
V
Vova Efanov2021-05-10 23:21:39
Python
Vova Efanov, 2021-05-10 23:21:39

Sqlite3.OperationalError: table stats has no column named user_id?

class SQLighter:
  def __init__(self, database):
      self.connection = sqlite3.connect(database, check_same_thread = False)
      self.cursor = self.connection.cursor()
      self.cursor.execute("CREATE TABLE IF NOT EXISTS stats (user_id INT, user_name TEXT, survived INT, infected INT)")
  def add_user(self, id, name, survived, infected): 
      with self.connection:
          return self.cursor.execute("""INSERT INTO `stats` (user_id, user_name, survived, infected) VALUES (?,?,?,?)""", (id, name, survived, infected))
  def get_nick(self, id):
      with self.connection:
          return self.cursor.execute("SELECT user_id FROM stats WHERE id = ?", (id, )).fetchall()
  def set_fast(self, id):
      with self.connection:
          return self.cursor.execute("UPDATE stats SET infected=X WHERE id=?", (id))

sql_lighter.get_nick(754651730)
sql_lighter.get_nick(982543922)

Writes an error in the title of the topic

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yupiter7575, 2021-05-10
@NoPressF

You are looking for an id column that you did not create. Questions?

M
MichaelMih, 2021-05-10
@MichaelMih

def __init__(self, database):
      self.connection = sqlite3.connect(database, check_same_thread = False)
      self.cursor = self.connection.cursor()
      self.cursor.execute("CREATE TABLE IF NOT EXISTS stats (user_id INT, user_name TEXT, survived INT, infected INT)")
      self.connection.commit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question