Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] MySQL - Generated Unique Key too long #1710

Closed
ghost opened this issue Jun 21, 2013 · 3 comments
Closed

[BUG] MySQL - Generated Unique Key too long #1710

ghost opened this issue Jun 21, 2013 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 21, 2013

If you try to make many columns as unique key, laravel is writing each column name after each other and is not cutting them after the max length.

For example, first_name, last_name, phone and company_name:

You will get following error message by running the migrate command.

[Exception]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table customers add unique customers_first_name_last_name_company_name_phone_unique(first_name, last_name, company_name, phone))

@taylorotwell
Copy link
Member

Just specify the index name yourself in that case. You can pass the name of the name as a second param.

@ghost
Copy link
Author

ghost commented Aug 12, 2016

Just in case someone stumbles across this: The problem isn't the length of the name of the index but the combined field length of the columns that are indexed.

Solution is to restrict the length of the individual columns, e.g. specify a max length for first_name, last_name etc. in the example above, i.e. $table->string('first_name', 50);

See http://stackoverflow.com/questions/23786359/laravel-migration-unique-key-is-too-long-even-if-specified

@necodon
Copy link

necodon commented Apr 6, 2017

I see the same question with use the laravel5.4 and now it's sloved, the first thing make sure you can see the welcome.blade.php,and then ,change the app\AppServiceProvider.php,

use Illuminate\Support\Facades\Schema;

public function boot()
{
Schema::defaultStringLength(191);
}

now ,have a test,good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants