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:
We want to insert a row of data, this row of data will be passed id_card
in, passwd
two fields. ( name
, problem
, answer
can be empty)
sql = "insert into user(id_card, passwd) values({}, '{}', '{}');".format(a, b, c)
What you want to pass into the table user
is the id_card
sum passwd
field, but after the values you have given him three values a
, b
, , . c
Only 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_card
is the string type, but the integer type is passed in here. Does not match.
In addition, one more word: the type of the values
value 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 values
whether 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! ! ! ! ! !