记一次MYSQL建表失败得bug(暂未解决!,求助)

CREATE TABLE `SUIT` (
`id` INTEGER(11) NOT NULL AUTO_INCREMENT,
`acId` INTEGER(11) NULL COMMENT '活动ID',
`name` VARCHAR(64) NULL COMMENT '套装名称',
`discountA1` decimal(8,2) NOT NULL COMMENT 'A2 折扣幅度',
`discountA2` decimal(8,2) NOT NULL COMMENT 'A2折扣',
`discountA3` decimal(8,0) NOT NULL COMMENT 'A3 折扣',
`discountB` decimal(8,2) NOT NULL COMMENT 'B 折扣',
`discountRetail` decimal(8,2) NOT NULL COMMENT '零售折扣',
`state` INTEGER(1) NOT NULL DEFAULT 0 COMMENT '销售状态;0:正常、1:下架',
`sort` INTEGER(4) NOT NULL DEFAULT 0 COMMENT '排序',
`createdBy` INTEGER(11) NULL,
`createdOn` DATETIME NULL,
`modifiedBy` INTEGER(11) NULL,
`modifiedOn` DATETIME NULL,
PRIMARY KEY (`id`) 
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COMMENT = '装备套装定义';
CREATE TABLE `SUIT_EQUIPMENT` (
`id` INTEGER(11) NOT NULL AUTO_INCREMENT,
`suitId` INTEGER(11) NOT NULL COMMENT '套装ID',
`articleNumber` VARCHAR(64) NULL COMMENT '货号',
`createdBy` INTEGER(11) NULL,
`createdOn` DATETIME NULL,
PRIMARY KEY (`id`) ,
INDEX `IDX_SUIT_EQUIPMENT_SUIT` (`suitId` ASC) USING HASH
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COMMENT = '套装装备定义';


CREATE TABLE `ACTIVITY_CONFIG` (
`id` INTEGER(11) NOT NULL AUTO_INCREMENT,
`type` INTEGER(2) NOT NULL COMMENT '常规、节日',
`name` VARCHAR(128) NULL COMMENT '活动名称',
`startTime` DATETIME NULL,
`endTime` DATETIME NULL,
`state` INTEGER(1) NULL COMMENT '活动状态',
`createdBy` INTEGER(11) NOT NULL,
`createdOn` DATETIME NOT NULL,
`modifiedBy` INTEGER(11) NULL,
`modifiedOn` DATETIME NULL,
PRIMARY KEY (`id`) 
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COMMENT = '活动配置定义';

ALTER TABLE `SUIT_EQUIPMENT` ADD CONSTRAINT `fk_SUIT_EQUIPMENT` FOREIGN KEY (`suitId`) REFERENCES `SUIT` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE `SUIT` ADD CONSTRAINT `fk_SUIT` FOREIGN KEY (`acId`) REFERENCES `ACTIVITY_CONFIG` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

原因:创建了三个表SUIT,ACTIVITY_CONFIG,SUIT_EQUIPMENT,和外键关联,之后删除了表SUIT(具体怎么删得不清楚,反正表找不到了),此时重新创建表,报错!

报错信息:

1005 - Can't create table 'newstack_db.SUIT' (errno: 150)  mysql报错

执行:

show engine innodb status;

查看错误信息:

------------------------
LATEST FOREIGN KEY ERROR
------------------------
181220 17:57:42 Error in foreign key constraint of table newstack_db/SUIT:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
  CONSTRAINT "fk_SUIT" FOREIGN KEY ("acId") REFERENCES "ACTIVITY_CONFIG" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION

此时执行

SELECT * FROM information_schema.KEY_COLUMN_USAGE;
 或
SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE CONSTRAINT_NAME like '%s%'

查询所有涉及得外键,并未找到相关外键,此时去删除表ACTIVITY_CONFIG;

DROP TABLE IF EXISTS `ACTIVITY_CONFIG`;
-- 删除报错

-- [SQL]DROP TABLE IF EXISTS `ACTIVITY_CONFIG`;
-- [Err] 1217 - Cannot delete or update a parent row: a foreign key constraint fails
-- 详细信息: 
-- ----------------------
LATEST FOREIGN KEY ERROR
------------------------
181221 13:25:28  Cannot drop table `newstack_db`.`ACTIVITY_CONFIG`
because it is referenced by `newstack_db`.`SUIT`
------------


--  百度后执行了下面得操作,成功删除表,
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `ACTIVITY_CONFIG`;
SET FOREIGN_KEY_CHECKS = 1;

成功删除表ACTIVITY_CONFIG后,创建SUIT,依然失败,至此,找不到办法了。。。。哭。。。。。。。。。++_++

有没有有解决办法得小哥哥小姐姐们? 改个表名啥的方法就算了,我是为了解决这个问题,不是建表。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值