S
S
samperirrrrr2020-12-04 22:43:37
Python
samperirrrrr, 2020-12-04 22:43:37

Why do I get pymysql.err.OperationalError:?

Help me get error - pymysql.err.OperationalError: (1364, "Field 'id' doesn't have a default value")
code below.

from connection import connect

def register(user_id):
  connection = connect()
  try:
    with connection.cursor() as cursor:
      result = cursor.execute(f"SELECT * FROM accounts WHERE uid={user_id}")
      xiy = cursor.fetchone()
      if result == 0:
        cursor.execute(f'INSERT INTO accounts(uid) VALUES({user_id})')
        connection.commit()
      else:
        return xiy
  finally:
    connection.close()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SKEPTIC, 2020-12-04
@pro100chel

In your table id is not filled in automatically. Are you able to read?
Put in phpmyadmin or through what you administer the database there the id field the auto-increment parameter and everything will be chiki bunches.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question