Hangfire.MySqlStorage icon indicating copy to clipboard operation
Hangfire.MySqlStorage copied to clipboard

"#1071 - Specified key was too long; max key length is 767 bytes

Open clayu opened this issue 6 years ago • 5 comments

CREATE TABLE `Set` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Key` varchar(100) NOT NULL,
  `Value` varchar(256) NOT NULL,
  `Score` float NOT NULL,
  `ExpireAt` datetime DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `IX_Set_Key_Value` (`Key`,`Value`)
) ENGINE=InnoDB  CHARSET=utf8;

The problem occurs with MySql 5.6 on db initialization. It appears that varchar(256) is the offender, if it is changed to varchar(255) it executes correctly.

No pull request as I'm not sure if 256 is strictly required.

clayu avatar May 15 '18 20:05 clayu

I have this issue too, it occurs on MySql 5.6 on a Windows installation

silversens avatar Jul 12 '18 13:07 silversens

I can confirm I am also getting this problem with V2.0.0 of Hangfire.MySqlStorage and MySql 5.6.41

wiggydave10 avatar Jan 29 '19 15:01 wiggydave10

Got the same issue and found a workaround. Got the install.sql file from the former release (1.0.5) and run to create folder structure before running the program. The charset is different (latin1) but can be changed later if necessary.

https://raw.githubusercontent.com/arnoldasgudas/Hangfire.MySqlStorage/5d91c44e58ceb11b67ac733287172550e301bc8c/Hangfire.MySql/Install.sql

sajithk avatar Apr 11 '19 07:04 sajithk

we can update install.sql like this:

-- ----------------------------
-- Table structure for `Set`
-- ----------------------------
CREATE TABLE `[tablesPrefix]Set` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Key` nvarchar(100) NOT NULL,
  `Value` nvarchar(100) NOT NULL,
  `Score` float NOT NULL,
  `ExpireAt` datetime DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `IX_[tablesPrefix]Set_Key_Value` (`Key`,`Value`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

then excute install.sql on MySql 5.6 without no error.

and set PrepareSchemaIfNecessary = false

870158446 avatar Dec 12 '20 07:12 870158446

Works like a charm, life saving workaround, thanks

ewarudol avatar Feb 19 '21 08:02 ewarudol