0

I've been getting the error "mysql.connector.errors.DataError: 1136 (21S01): Column count doesn't match value count at row 1" after trying to enter the user details, but I don't see why:

def userEntry():
    if myConnection:
        cursor = myConnection.cursor()
        createTable = """CREATE TABLE IF NOT EXISTS C_DETAILS(CID INT(11) AUTO_INCREMENT PRIMARY KEY, C_NAME VARCHAR(30),
        C_ADDRESS VARCHAR(30), C_AGE INT(2),
        C_COUNTRY VARCHAR(30), P_NO INT(10), C_EMAIL VARCHAR(30))"""
        cursor.execute(createTable)
        name = input("Enter Customer Name : ")
        address = input("Enter Customer Address : ")
        age = int(input("Enter Customer Age : "))
        nationality = input("Enter Customer Country : ")
        phoneno = int(input("Enter Customer Contact Number : "))
        email = input("Enter Customer Email : ")
        sql = "INSERT INTO C_Details VALUES(%s, %s, %s, %s, %s, %s)"
        values = (name, address, age, nationality, phoneno, email)
        cursor.execute(sql, values)
        cursor.execute("COMMIT")
        print("\nNew Customer Entered In The System Successfully!")
        cursor.close()
    else:
        print("\nERROR ESTABLISHING MYSQL CONNECTION!")

I'm assuming that it's because of my AUTO_INCREMENT field, but I read that there's no need to add a parameter for that type of field.

Does anyone know what might be the issue?

Ben Kitai
  • 9
  • 2
  • If you aren't providing values for _all_ the columns in the table in an `INSERT`, you need to list the columns that you _are_ providing values for (in the same order as the values. `INSERT INTO mytable (col1, col2, col3) VALUES (v1, v2, v3)`. The answers to the linked duplicate demonstrate this, and also ways to provide a "value" for the autoincrement column so that you don't need to list them all. – snakecharmerb Dec 02 '22 at 19:02

0 Answers0