My MySQL Version is 8.0.34 CE (64 bits)
And my table is as below
CREATE TABLE `t_report_subscriptions` (
`subscr_id` int NOT NULL AUTO_INCREMENT,
`report_header_id` varchar(700) NOT NULL,
`user_id` varchar(45) NOT NULL,
`update_type` varchar(45) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`modified_date` datetime DEFAULT NULL,
`source_system_id` int DEFAULT NULL,
PRIMARY KEY (`subscr_id`),
UNIQUE KEY `uq_reportSubsriptions` (`report_header_id`,`user_id`,`source_system_id`),
KEY `report_id_fk_idx` (`report_header_id`,`source_system_id`),
CONSTRAINT `fk_report_id` FOREIGN KEY (`report_header_id`, `source_system_id`) REFERENCES `l_report_header_data` (`REPORT_HEADER_ID`, `SOURCE_SYSTEM_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
I am trying to increase the length of the 'user_id' column from 45 to 256 as follows
alter table t_report_subscriptions modify column user_id varchar(256) NOT NULL;
And getting the following error
Error Code: 1071. Specified key was too long; max key length is 3072 bytes
I tried dropping all the constraints and index of the table then increase the size of the column and then re-creating the constraints and index, but still it does not work
I have dropped the constraints and index as below
ALTER TABLE t_report_subscriptions drop index `report_id_fk_idx`;
ALTER TABLE t_report_subscriptions drop index `uq_reportSubsriptions`;
ALTER TABLE t_report_subscriptions DROP FOREIGN KEY fk_report_id;
Then increased the length of the 'user_id' column as below
alter table t_report_subscriptions modify column user_id varchar(256) NOT NULL;
Then re-creating the constraints and index as below
ALTER TABLE t_report_subscriptions ADD CONSTRAINT `fk_report_id` FOREIGN KEY (`report_header_id`, `source_system_id`) REFERENCES `l_report_header_data` (`REPORT_HEADER_ID`, `SOURCE_SYSTEM_ID`);
ALTER TABLE t_report_subscriptions add index `report_id_fk_idx` (`report_header_id`,`source_system_id`);
But when i try to re-create the unique constraint as below i get the following error
ALTER TABLE t_report_subscriptions ADD CONSTRAINT `uq_reportSubsriptions` UNIQUE(`report_header_id`,`user_id`,`source_system_id`);
The error is
16:12:43 ALTER TABLE t_report_subscriptions ADD CONSTRAINT `uq_reportSubsriptions` UNIQUE(`report_header_id`,`user_id`,`source_system_id`) Error Code: 1071. Specified key was too long; max key length is 3072 bytes 0.000 sec
I have referred multiple links
why this error occur #1071 - Specified key was too long; max key length is 1000 bytes?
Mysql ERROR 1071 (42000): Specified key was too long; max key length is 3072 bytes
MySQL Error #1071 - Specified key was too long; max key length is 767 bytes
But not able to increase the size of the column. Any suggestions/help