mysql prompts Column count doesn't match value count at row 1 error

When we add information to the database, we may encounter the following errors:
Column count doesn't match value count at row 1
This error means that the number of fields passed into the table is not the same as the number of values.
I summarized it, There are three main error-prone points:

1. The number of fields to be passed into the table is not equal to the number of values ​​after values.

eg: There are the following 6 fields in a table:
insert image description here
We want to insert a row of data, this row of data will be passed id_cardin, passwdtwo fields. ( name, problem, answercan be empty)

sql = "insert into user(id_card, passwd) values({}, '{}', '{}');".format(a, b, c)

What you want to pass into the table useris the id_cardsum passwdfield, but after the values ​​you have given him three values a, b, , . cOnly two values ​​should be given correspondingly.

2. The value type of values ​​does not match the field type defined in the table

For example, the following code:

sql = "insert into user(id_card, passwd) values({}, '{}';".format(127, '111')

What I define in the table id_cardis the string type, but the integer type is passed in here. Does not match.

In addition, one more word: the type of the valuesvalue here has nothing to do with the type of the parameter passed in.
For example: values({})this is an integer, values('{}')which is a string type
. The point of difference is valueswhether the one in and {}is enclosed in single quotes. If it is enclosed, it is a string, and if it is not, it is an integer. And format()has nothing to do with the parameter type.

3. Note that commas, brackets, and semicolons must be written in American style. Don't pay attention to writing them in Chinese! ! ! ! ! ! !

This time I was looking for this error for 30 minutes, I thought it was the code, field and other reasons, but it was not! ! ! ! ! !

Guess you like

Origin blog.csdn.net/qq_43842093/article/details/124774774
Recommended