Ron Clough
Ron Clough

Reputation: 13

MySQL: Column Count Doesn't Match Value Count

UPDATE ** Thank you for everyone's help. It is appreciated. It was a trigger that was being used, and not an issue with the Insert. I had tunnel visioned on the insert and forgot all about checking the trigger.


I can't for the life of me figure out the problem with this mysql insert:

INSERT INTO campaigns (camp_id,camp_name,camp_desc,camp_created,camp_creator,camp_start,camp_end,camp_active)
VALUES (null,'Clinic','2013 Clinic',now(),'user','2013-10-21','2013-10-25',1);

Table:

Field           Type          Null    Key   Default             Extra
===========================================================================================
camp_id         int(12)       NO      PRI               auto_increment
camp_name           varchar(32)   NO            
camp_desc           varchar(255)  YES           
camp_created    timestamp     NO      CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
camp_creator    varchar(16)   NO            
camp_start      date          NO            
camp_end        date          NO            
camp_active         int(1)        NO        

Any help is appreciated.

Per Requests: SHOW CREATE TABLE campaigns:

CREATE TABLE `campaigns` 
( `camp_id` int(12) NOT NULL AUTO_INCREMENT,
  `camp_name` varchar(32) NOT NULL,
  `camp_desc` varchar(255) DEFAULT NULL,
  `camp_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP 
       ON UPDATE CURRENT_TIMESTAMP,
  `camp_creator` varchar(16) NOT NULL,
  `camp_start` date NOT NULL,
  `camp_end` date NOT NULL,
  `camp_active` int(1) NOT NULL,
  PRIMARY KEY (`camp_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1

Upvotes: 1

Views: 1577

Answers (2)

juergen d
juergen d

Reputation: 204746

You need quotes around your dates

INSERT INTO campaigns( camp_id, camp_name, camp_desc, 
                       camp_created, camp_creator, camp_start, 
                       camp_end, camp_active)
VALUES (null, 'Clinic', '2013 Clinic',
        now(), 'user', '2013-10-21',
        '2013-10-25', 1);

If you still have errors and especially the "Column Count Doesn't Match Value Count" error, then the most probable explanation is a trigger that tries to do another Insert.

Upvotes: 5

Sashi Kant
Sashi Kant

Reputation: 13455

Other than the error answered by juergen, you will also face an issue where you are having a column named camp_id which you have declared as NOT NULL and you are inserting NULL to it.

IF camp_id is Auto Increment then Try this::

INSERT INTO campaigns( camp_name, camp_desc, 
                       camp_created, camp_creator, camp_start, 
                       camp_end, camp_active)
VALUES ('Clinic', '2013 Clinic',
        now(), 'user', '2013-10-21',
        '2013-10-25', 1);

Upvotes: 0

Related Questions