Mysql Error: ER_TOO_LONG_KEY

Asked

Viewed 91 times

1

I’m getting the error in Mysql and don’t know how to fix it.

Below is listed the output:

code: 'ER_TOO_LONG_KEY',
  errno: 1071,
  sqlMessage: 'Specified key was too long; max key length is 767 bytes',
  sqlState: '42000',
  index: 0,
  sql: 'alter table `positions` add unique `positions_name_unique`(`name`)' 
}

Image of the table structure:
-> http://prntscr.com/jrdihn

The charset used is UTF-8.

  • Enter in the question the table structure, type, charset used etc.

  • I edited the question.

  • I just tried. Unsuccessful. Same error is received.

  • Try a very low value, type name(20)

  • Still doesn’t work (had changed to 10).

  • The funny thing is that on my computer it works. It is only on the server that the error exists. ._.

  • @dvd, turned out it was decreasing even... I ended up making a mistake at the time of decreasing and so I commented above. You can put the answer to mark. :)

Show 2 more comments

1 answer

2


inserir a descrição da imagem aqui

The most you can use in columns utf8mb4 (in INNODB table) would be 191 (767/4 = 191) because it uses 4 bytes per character.

Decrease the value in name(200) to stay within the limit.

More information you can refer to official Mysql documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.