0

如何在没有分配键名且自动增加主键的情况下向 mysql 插入新记录?

请参阅PHP mySQL - 将新记录插入表中,主键自动递增
将第一个值更改为 DEFAULT ,但仍然发生相同的错误

在此处输入图像描述

表结构:

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);
4

1 回答 1

1

unq_config_key_zen列上有一个唯一键configuration_key,因此您不能插入具有相同configuration_key值的行。

 UNIQUE KEY `unq_config_key_zen` (`configuration_key`),
于 2012-12-30T02:20:35.863 回答