Duplicate entry '' for key 'PRIMARY'

一查,发现表没有设置自增长。

尝试增加修改表,添加自增长。

ALTER TABLE sh_incentive_item MODIFY id SMALLINT UNSIGNED AUTO_INCREMENT;

报错

[SQL] ALTER TABLE sh_incentive_item MODIFY id SMALLINT UNSIGNED AUTO_INCREMENT;
[Err] 1833 - Cannot change column 'id': used in a foreign key constraint 'FK_sh_incentive_item_id' of table 'storehelper.sh_incentive'

发现是因为外键的影响,不能随便的更改表结构。

要想更改表结构,首先要把基层的表修改了。

A表 作为B表的外键,A表不能随便修改。

B表 有A表的外键,必须先处理好B,然后A才能修改。

索性,我就把表中的外键全部去除。

原SQL

SET FOREIGN_KEY_CHECKS=;

-- ----------------------------
-- Table structure for `sh_incentive`
-- ----------------------------
DROP TABLE IF EXISTS `sh_incentive`;
CREATE TABLE `sh_incentive` (
`id` int() NOT NULL COMMENT '编号',
`item_id` int() DEFAULT NULL COMMENT '名称',
`agent_id` int() DEFAULT NULL COMMENT '关联代理商',
`money` double(,) NOT NULL COMMENT '金额',
`year` int() NOT NULL COMMENT '年份',
`month` int() NOT NULL COMMENT '月份',
`addtime` int() NOT NULL COMMENT '添加时间',
PRIMARY KEY (`id`),
KEY `FK_sh_incentive_item_id` (`item_id`),
CONSTRAINT `FK_sh_incentive_item_id` FOREIGN KEY (`item_id`) REFERENCES `sh_incentive_item` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='激励设定'; -- ----------------------------
-- Records of sh_incentive
-- ---------------------------- -- ----------------------------
-- Table structure for `sh_incentive_item`
-- ----------------------------
DROP TABLE IF EXISTS `sh_incentive_item`;
CREATE TABLE `sh_incentive_item` (
`id` int() NOT NULL COMMENT '编号',
`name` varchar() NOT NULL COMMENT '名称',
`intro` varchar() NOT NULL COMMENT '说明',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统激励项'; -- ----------------------------
-- Records of sh_incentive_item
-- ---------------------------- -- ----------------------------
-- Table structure for `sh_opener_bonus`
-- ----------------------------
DROP TABLE IF EXISTS `sh_opener_bonus`;
CREATE TABLE `sh_opener_bonus` (
`id` int() NOT NULL COMMENT '编号',
`opener_id` int() DEFAULT NULL COMMENT '员工编号',
`incentive_id` int() DEFAULT NULL COMMENT '激励条件id',
`remark` varchar() DEFAULT NULL COMMENT '备注说明',
`addtime` int() DEFAULT NULL COMMENT '记录时间',
PRIMARY KEY (`id`),
KEY `FK_sh_openernus_opener_id` (`opener_id`),
KEY `FK_sh_openernus_incentive_id` (`incentive_id`),
CONSTRAINT `FK_sh_openernus_incentive_id` FOREIGN KEY (`incentive_id`) REFERENCES `sh_incentive` (`id`),
CONSTRAINT `FK_sh_openernus_opener_id` FOREIGN KEY (`opener_id`) REFERENCES `sh_opener` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='拓展员奖金'; -- ----------------------------
-- Records of sh_opener_bonus
-- ---------------------------- -- ----------------------------
-- Table structure for `sh_opener_bonus_payment`
-- ----------------------------
DROP TABLE IF EXISTS `sh_opener_bonus_payment`;
CREATE TABLE `sh_opener_bonus_payment` (
`id` int() NOT NULL COMMENT '编号',
`opener_id` int() NOT NULL COMMENT '拓展员',
`agent_id` int() DEFAULT NULL COMMENT '代理商',
`money` double(,) NOT NULL COMMENT '金额',
`trode_number` varchar() NOT NULL COMMENT '转账流水号',
`addtime` int() NOT NULL COMMENT '添加时间',
PRIMARY KEY (`id`),
KEY `FK_sh_openerent_opener_id` (`opener_id`),
CONSTRAINT `FK_sh_openerent_opener_id` FOREIGN KEY (`opener_id`) REFERENCES `sh_opener` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='拓展员奖金发放'; -- ----------------------------
-- Records of sh_opener_bonus_payment
-- ----------------------------

把外键统统去掉

-- ----------------------------
-- Table structure for `sh_opener_bonus_payment`
-- ----------------------------
DROP TABLE IF EXISTS `sh_opener_bonus_payment`;
CREATE TABLE `sh_opener_bonus_payment` (
`id` int() NOT NULL COMMENT '编号',
`opener_id` int() NOT NULL COMMENT '拓展员',
`agent_id` int() DEFAULT NULL COMMENT '代理商',
`money` double(,) NOT NULL COMMENT '金额',
`trode_number` varchar() NOT NULL COMMENT '转账流水号',
`addtime` int() NOT NULL COMMENT '添加时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='拓展员奖金发放'; -- ----------------------------
-- Table structure for `sh_opener_bonus`
-- ----------------------------
DROP TABLE IF EXISTS `sh_opener_bonus`;
CREATE TABLE `sh_opener_bonus` (
`id` int() NOT NULL COMMENT '编号',
`opener_id` int() DEFAULT NULL COMMENT '员工编号',
`incentive_id` int() DEFAULT NULL COMMENT '激励条件id',
`remark` varchar() DEFAULT NULL COMMENT '备注说明',
`addtime` int() DEFAULT NULL COMMENT '记录时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='拓展员奖金'; -- ----------------------------
-- Records of sh_opener_bonus
-- ---------------------------- -- ----------------------------
-- Table structure for `sh_incentive`
-- ----------------------------
DROP TABLE IF EXISTS `sh_incentive`;
CREATE TABLE `sh_incentive` (
`id` int() NOT NULL COMMENT '编号',
`item_id` int() DEFAULT NULL COMMENT '名称',
`agent_id` int() DEFAULT NULL COMMENT '关联代理商',
`money` double(,) NOT NULL COMMENT '金额',
`year` int() NOT NULL COMMENT '年份',
`month` int() NOT NULL COMMENT '月份',
`addtime` int() NOT NULL COMMENT '添加时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='激励设定'; -- ----------------------------
-- Records of sh_incentive
-- ---------------------------- -- ----------------------------
-- Table structure for `sh_incentive_item`
-- ----------------------------
DROP TABLE IF EXISTS `sh_incentive_item`;
CREATE TABLE `sh_incentive_item` (
`id` int() NOT NULL COMMENT '编号',
`name` varchar() NOT NULL COMMENT '名称',
`intro` varchar() NOT NULL COMMENT '说明',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统激励项'; -- ----------------------------
-- Records of sh_incentive_item
-- ----------------------------

上面的顺序很重要哦。顺序有误,就不能执行成功!

处理好后,就可以添加自增长了。

最新文章

  1. JSON学习
  2. Circuit Breaker Pattern(断路器模式)
  3. tls/ssl证书生成和格式转换
  4. 70.Android开发知识点总结
  5. STM32的寄存器控制SDA_IN()/SDA_OUT()
  6. Android 自动换行流式布局的RadioGroup
  7. 华为的JAVA面试题及答案(部分)
  8. Joseph cicyle's algorithm
  9. zepto源码学习-06 touch
  10. Android之读取 AndroidManifest.xml 中的数据
  11. WPF采用MVVM模式(绑定:纯前台、命令:触发器绑定命令)
  12. 在PHP中PDO解决中文乱码问题
  13. iOS弹出底部视图简单实现
  14. 前端安全之CSRF攻击
  15. Swift基础之音乐播放随机变换着色板
  16. 手机号读取城市数据库2018年3月excel版
  17. linux下有名管道进程通信
  18. Getting Started with Processing 第四章总结
  19. mysql 复制表数据,表结构的3种方法
  20. Codeforces Round #222 (Div. 1) B. Preparing for the Contest 二分+线段树

热门文章

  1. How to Shorten the Paper
  2. ORACLE rowid切分大表
  3. Ubuntu-12.04-server 配置修改静态 IP地址
  4. Linux档案与目彔的基本操作(查看与权限)
  5. [原创]使用Pandoc实现Markdown文件转PDF文件
  6. [原创]HEXO博客搭建日记
  7. EditText的一些属性及用法
  8. 项目评价及第五周PSP的发布
  9. Java核心知识点学习----多线程并发之线程间的通信,notify,wait
  10. 小甲鱼python视频第七讲(课后习题)