Solve MySql Engine Error – Import Database Called Specified key was too long; max key length is 767 bytes

0
85

If anyone is having issues with INNODB / Utf-8 trying to put an UNIQUE index on a VARCHAR(256) field, switch it to VARCHAR(255). It seems 255 is the limitation.

Calculation to Understand Byte:

The number of allowed characters just depends on your character set. UTF8 may use up to 3 bytes per character, utf8mb4 up to 4 bytes, and latin1 only 1 byte. Thus for utf8 your key length is limited to 255 characters, since 3*255 = 765 < 767

When Worked in your Local Server as a Laravel Website then it has default Configuration to when Migrate Each Table in Database.

Like When Create Action Migrate Table –

Specify a smaller length for your e-mail:

Which is the default, actually:

And you should be good.

When Use InnoDb Engine your System Laravel Configaration you should must follow :

Must identify Value of Each Column/Attribute.

For Laravel 5.4 you can find a solution in this Laravel 5.4: Specified key was too long error,

Make Solution :

Find Out

Put Bellow Code into There

You can Change Degit what you need

Solution

And if you intentionally want to use the correct future-default (starting from Laravel 5.4) UTF8 multi-byte utf8mb4 support for ? then start to fix ? your database configuration.

In Laravel config/database.php define:

How to change DATABASE engine to InnoDB?

 

You can use same above methods to INNODB instead of MyISAM.

Otherwise, You can change manually with below is a syntax to change storage engine to InnoDB.

To convert all DBNAME’s InnoDB Tables to MyISAM