I'm using Mysql 5.6.46
.
And the final sql execute in my code is
REPLACE ...
.
I'm using multi thread way to batch insert data into my db table.
The question is the AUTO_INCREMENT
is less than my table max ID
, and then I can not write data into this table for it always raise error Duplicate entry '31245418' for key 'PRIMARY'
SELECT AUTO_INCREMENT
FROM information_schema.tables WHERE table_schema='db' AND table_name='table';
# 31245419
SELECT id FROM spend_daily_level ORDER BY id DESC LIMIT 1
# 31247125
How can I avoid this problem? Thanks
I will provide more detail info if it's necessary
Update more info
CREATE TABLE `spend_daily_level` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`active` tinyint(1) NOT NULL ,
`created_time` datetime(6) NOT NULL ,
`updated_time` datetime(6) NOT NULL ,
`date` date NOT NULL ,
`system_value` decimal(16,2) NOT NULL ,
`checked_value` decimal(16,2) NOT NULL ,
`account_id` int(11) NOT NULL ,
`sale_leader_id` int(11) DEFAULT NULL ,
`account_status` tinyint(3) DEFAULT '1' ,
PRIMARY KEY (`id`),
UNIQUE KEY `spend_daily_level_date_account_id_f38b1186_uniq` (`date`,`account_id`),
KEY `spend_daily_level_account_id_f6df4f99_fk_account_id` (`account_id`),
KEY `sale_leader_id` (`sale_leader_id`),
KEY `date_active` (`active`,`date`),
CONSTRAINT `spend_daily_level_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`),
CONSTRAINT `spend_daily_level_ibfk_2` FOREIGN KEY (`sale_leader_id`) REFERENCES `sale_leader` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31245419 DEFAULT CHARSET=utf8 COMMENT='daily_spend'