2

I have a migration file for my php project. I am getting this error

Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

I do understand this issue is due to varchar(512) and charset - UTF8 but how do I solve this? I cannot change in my migration script. Can I change some properties in my.ini of MySql?

CREATE TABLE if not exists usermaster (
  user_id bigint(20) NOT NULL,
  username varchar(512) NOT NULL,
  PRIMARY KEY (user_id,username),
   KEY fk_um_idx (user_id),
  CONSTRAINT fk_um_idx FOREIGN KEY (user_id) REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

1 Answers1

0

The following comment on a duplicate topic gives 2 possibilities if you insist on keeping the length of the username on 512: https://stackoverflow.com/a/41298282/5987517

I think the best solution in our case is to change your encoding from UTF-8 to latin1_general_ci

WesselV
  • 336
  • 2
  • 10