报错信息

Column count doesn't match value count at row 1;
Column count doesn't match value count at row 1;

原因:

插入时的数据个数与表中的字段个数不一致,问题基本都出在Insert语句中

  • LOL 结构表为测试表为例进行说明,该表包括4列。
mysql> DESC `LOL`;
+------------+-------------+------+-----+---------+----------------+
| Field      | Type        | Null | Key | Default | Extra          |
+------------+-------------+------+-----+---------+----------------+
| id         | int(11)     | NO   | PRI | NULL    | auto_increment |
| hero_title | varchar(32) | YES  | MUL | NULL    |                |
| hero_name  | varchar(32) | YES  |     | NULL    |                |
| price      | int(10)     | YES  |     | NULL    |                |
+------------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

错误例1:

如下,明显为前后列数不等造成的;

-- 报错:Column count doesn't match value count at row 1
INSERT INTO `LOL` (`id`, `hero_title`, `hero_name`, `price`) VALUES (null, 'D刀锋之影', '泰隆');

-- 报错:Column count doesn't match value count at row 1
INSERT INTO `LOL` (`id`, `hero_title`, `hero_name`) VALUES (null, 'D刀锋之影', '泰隆', '6300');

错误例2:

如下:本表有四列,前面没有声明插入列,MySQL默认为全部的列,应插入4个值;但后面插入值的数量不对,故报错。

-- 报错:Column count doesn't match value count at row 1
INSERT INTO `LOL` VALUES (null, 'D刀锋之影', '泰隆');
解决方法:

检查表中的字段数与SQL语句中所插入的数据字段数是否一致,以及SQL语句前后列数量是否一致