Mustaque Ahmed
Mustaque Ahmed

Reputation: 135

Error : 1071, Specified key was too long; max key length is 1000 bytes

I want to import a sql file in my database getting this error 1071, Specified key was too long; max key length is 1000 bytes

here is my code for related table.

DROP TABLE IF EXISTS `model_has_permissions`;

CREATE TABLE `model_has_permissions` (
  `permission_id` int(10) unsigned NOT NULL,
  `model_type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `model_id` bigint(20) unsigned NOT NULL,
  PRIMARY KEY (`permission_id`,`model_id`,`model_type`),
  KEY `model_has_permissions_model_id_model_type_index` (`model_id`,`model_type`),
  CONSTRAINT `model_has_permissions_permission_id_foreign` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Upvotes: -2

Views: 1152

Answers (1)

Rick James
Rick James

Reputation: 142503

Plan A: Don't use more than 191 for number of characters in model_type.

Plan B: Normalize model_type.

Plan C: Change model_type to `CHARACTER SET ascii, if appropriate.

Other options: http://mysql.rjweb.org/doc.php/limits#767_limit_in_innodb_indexes

Upvotes: 2

Related Questions