mysql提示Column count doesn't match value count at row 1错误

We may encounter the following error when adding information to the database:
Column does not match value COUNT COUNT AT Row 1
of the error mean values and the number of incoming field value table is not the same as the number of
I sum up a bit, there are three error-prone points:

1. To the incoming values ​​of the number of fields and the following values ​​in the table are not equal number.

eg: a table in the following six fields:
Here Insert Picture Description
we want to insert a row of data, the data will be passed in this line id_card, passwdtwo fields. ( name, problem, answerCan be empty)

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

To pass table useris id_cardand the passwdfield, but behind the values you gave him a, b, cthree values. It should correspond to the only two values.

2.values ​​field type and value types defined in the table do not match

For example, we have the following code:

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

As defined in Table I id_cardis a string type, but here is the incoming integer. Does not match.

In addition, say one more thing: here valuesindependent of the type and value of the incoming parameter type.
For example: values({})This is an integer, values('{}')which is a type of string
type in the difference of emphasis valuesin {}including whether single quotes together, if that is enclosed in the string is not an integer. And with format()nothing to do in the parameter type.

3. Note the commas, parentheses, semicolons should use American's do not pay attention to the written Chinese language! ! ! ! ! ! !

I find this is a mistake 30 minutes, thought it was code field and other reasons, the result is not! ! ! ! ! !

Guess you like

Origin www.cnblogs.com/mljs/p/11568199.html