0

I have a table (as seen below), this is default from Laravel. However when i try and make the email column unique, i receive the following error:

ALTER TABLE `users` ADD UNIQUE(`email`);

MySQL said: Documentation
#1071 - Specified key was too long; max key length is 767 bytes

Table as seen in phpMyAdmin

View of table

Any thoughts?

The-WebGuy
  • 877
  • 5
  • 12
  • 25
  • 3
    Possible duplicate of [#1071 - Specified key was too long; max key length is 767 bytes](https://stackoverflow.com/questions/1814532/1071-specified-key-was-too-long-max-key-length-is-767-bytes) – Ivar Jan 14 '19 at 10:47
  • Like the error says a unique constraint can only be a max of 767 bytes. `utf8mb4` is up to 4 bytes per character, so 255 characters would be 1020 bytes. – Ivar Jan 14 '19 at 10:50
  • So changing it to utf8_bin worked – The-WebGuy Jan 14 '19 at 11:26

1 Answers1

-4

Try this

ALTER IGNORE TABLE users ADD UNIQUE(email);

Krishna
  • 438
  • 5
  • 18
  • 2
    Instead of just saying “try this”, could you explain why that would solve the problem? – JJJ Jan 14 '19 at 11:45