linjuming
linjuming

Reputation: 2157

How to insert new records to mysql with no key name assigned and with auto increasing primary key?

How to insert new records to mysql with no key name assigned and with auto increasing primary key?

refer to PHP mySQL - Insert new record into table with auto-increment on primary key
changed th first value to DEFAULT ,but still same error occurs

enter image description here

table structure:

DROP TABLE IF EXISTS `configuration_copy`;
CREATE TABLE `configuration_copy` (
  `configuration_id` int(11) NOT NULL auto_increment,
  `configuration_title` text NOT NULL,
  `configuration_key` varchar(255) NOT NULL default '',
  `configuration_value` text NOT NULL,
  `configuration_description` text NOT NULL,
  `configuration_group_id` int(11) NOT NULL default '0',
  `sort_order` int(5) default NULL,
  `last_modified` datetime default NULL,
  `date_added` datetime NOT NULL default '0001-01-01 00:00:00',
  `use_function` text,
  `set_function` text,
  PRIMARY KEY  (`configuration_id`),
  UNIQUE KEY `unq_config_key_zen` (`configuration_key`),
  KEY `idx_key_value_zen` (`configuration_key`,`configuration_value`(10)),
  KEY `idx_cfg_grp_id_zen` (`configuration_group_id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of configuration_copy
-- ----------------------------
INSERT INTO `configuration_copy` VALUES ('1', 'World Points', 'WORD_POINTS', '0', 'Points required upgrading to world grade', '1', '1', '0000-00-00 00:00:00', '2012-12-30 09:38:23', null, null);
INSERT INTO `configuration_copy` VALUES ('2', 'Iron Points', 'IRON_POINTS', '1000', 'Points required upgrading to iron grade', '1', '2', null, '0001-01-01 00:00:00', null, null);
INSERT INTO `configuration_copy` VALUES ('3', 'Bronze Points', 'BRONZE_POINTS', '2000', 'Points required upgrading to bronze grade', '1', '3', null, '0001-01-01 00:00:00', null, null);
INSERT INTO `configuration_copy` VALUES ('4', 'Silver Points', 'SILVER_POINTS', '3000', 'Points required upgrading to silver grade', '1', '4', null, '0001-01-01 00:00:00', null, null);
INSERT INTO `configuration_copy` VALUES ('5', 'Gold Points', 'GOLD_POINTS', '4000', 'Points required upgrading to gold grade', '1', '5', null, '0001-01-01 00:00:00', null, null);

Upvotes: 0

Views: 391

Answers (1)

zerkms
zerkms

Reputation: 255155

There is an unique key unq_config_key_zen on the configuration_key column, so you cannot insert rows that have the same configuration_key value.

 UNIQUE KEY `unq_config_key_zen` (`configuration_key`),

Upvotes: 1

Related Questions