0

I'm trying to add new values to the MySQL database table, but there is always an error. I am new to python programming so I don't really know how all of this works. the photo of the error is below.

def add_new():
    eq_name = t1.get()
    total2 = t2.get()
    query = "INSERT INTO Equipment(equipmentID, name, available, borrowed,  total) VALUES(NULL, %s, %s, %s, %s, NOW())"
    cursor.execute(query, (eq_name, total2, 0, total2 ))
    clear()

enter image description here

3
  • The problem described in this question doesn't have anything to do with tkinter so please remove that tag Commented Apr 21, 2021 at 17:16
  • the question (or problem) has also not much to do with python, maybe you should remove that tag too, and first learn SQL before learning python. Commented Apr 21, 2021 at 17:20
  • In stead of that picture, you also could have posted "ERROR 1136 (21S01): Column count doesn't match value count at row 1" Commented Apr 21, 2021 at 17:22

2 Answers 2

1
(equipmentID, name, available, borrowed,  total)
      ^         ^       ^          ^         ^
      1         2       3          4         5
(NULL, %s, %s, %s, %s, NOW())
  ^     ^   ^   ^   ^   ^
  1     2   3   4   5   6
Sign up to request clarification or add additional context in comments.

2 Comments

You beat me to it
thanks, I just didn't think that NOW() is also a value
0
  • You have 5 columns in the command insert and you are passing 6 values

  • If it’s auto increment, you don’t need to pass equipmentID

  • You can automatically retrieve the date and save it.

ALTER TABLE Equipment MODIFY COLUMN createdDt DATETIME DEFAULT CURRENT_TIMESTAMP()
query = "INSERT INTO Equipment(col1, col2, col3, col4, col5) VALUES(NULL, %s, %s, %s, %s, NOW())"
cursor.execute(query, (val1, val2, val3, val4, val5 ))

1 Comment

I guess you'd want to remove NOW() now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.