Hi guys,

In my production server, I am receiving this MySQL error: ER_TOO_LONG_KEY.
I don’t know how to solve this.

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`)' 

How can I solve this?
It is working fine in my local pc…


Look at the first answer. It says the limit was increased for MySQL 5.7 and above. You must have a version prior to MySQL 5.7 installed on your production server.

Remember, when you have programming questions, especially those that aren’t Adonis specific, Google is your friend. We have tools like stackoverflow now that make resolving issues really fast.


Also, just a tip for keeping things in sync, Docker is your friend! As long as both machines have the same docker version, you can practically guarantee identical environments


Is that a String?

if thats the case a quick fix is
table.string(‘positions_name_unique’, 150).unique()

change the length to 150.


Fixed reducing to:

table.string('...', 190)