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

Specified key was too long; max key length is 767 bytes #20627

Closed
kalidasweb opened this issue Aug 18, 2017 · 9 comments
Closed

Specified key was too long; max key length is 767 bytes #20627

kalidasweb opened this issue Aug 18, 2017 · 9 comments

Comments

@kalidasweb
Copy link

  • Laravel Version: 5.5 -- dev
  • PHP Version: PHP 7.1.8-2+ubuntu17.04.1+deb.sury.org+4
  • Database : 10.1.25-MariaDB

Description:

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add uni que users_email_unique(email))

Steps To Reproduce:

1.Create the new app
2.Set Env values
3.Run php artisan make:auth
4.Run php artisan migrate
5.Got Error

Steps To Fix:

1.Goto app/Providers/AppServiceProvider.php
2. Add \Illuminate\Support\Facades\Schema::defaultStringLength(191); in that boot method

is it really correct fix ?

@themsaid
Copy link
Member

Yes, check the documentation.

@kalidasweb
Copy link
Author

kalidasweb commented Aug 18, 2017

@themsaid thanks

check out https://laravel.com/docs/master/migrations/#creating-indexes

but if possible put some default values :)

@bbashy
Copy link
Contributor

bbashy commented Aug 18, 2017

10.2 MariaDB is now stable, any reason for not upgrading to fix this issue @kalidasweb?

@amenk
Copy link
Contributor

amenk commented Oct 9, 2017

I am confused .. is this fixed in current laravel versions or not?

@bbashy
Copy link
Contributor

bbashy commented Oct 9, 2017

@amenk There is no 'bug', 'fix' per se. It's because the default length is different. Either upgrade your MySQL/MariaDB versions or add the defaultStringLength(191); to boot method of AppServiceProvider.php.

@Ezyweb-uk
Copy link

I'm getting the same error in a Laravel project even after making various updates. I'm running the following versions on a local ampps server on Windows 10:
Apache 2.4.27
Php 7.1.8
MySql 5.6.35 InnoDB utf8_general_ci collation (changed from utf8mb4_general_ci)
Laravel 5.6.39

In AppServiceProvider.php near the top I've added:
use Illuminate\Support|Facades\Schema;

And in function boot I've added:
Schema::defaultStringLength(191);

In config/database.php I've changed charset tp 'utf8',collation to 'utf8_general_ci', and engine to 'InnoDB ROW_FORMAT=DYNAMIC'.

Using php artisan migrate:fresh I even still get the error if in the xyz_create_users_table.php I change $table->string('email')->inique(); to $table->string('email');. The first error says:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")
\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:144

I was wondering if the doctrine cache needed clearing but php app/console cache:clear said "could not open input file".

@ezcodepl
Copy link

I'm getting the same error in a Laravel project even after making various updates. I'm running the following versions on a local xampp server on Windows 10:
Apache 2.4.34
PHP 7.2.8
MariaDB 10.1.34
Laravel 5.7.26

Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table users (id int unsigned not null auto_increment primary key, name varchar(255) not null, email varchar(255) not null, email_verified_at timestamp null, password varchar(255) not null, remember_token varchar(100) null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

the problem exists to the version 5.4 laravel why no one will change so that you do not have to change every time you create a new project?

@devcircus
Copy link
Contributor

The exception that you pasted is not the same as the exception at issue here.

@devcircus
Copy link
Contributor

Need at least Maria 10.2.2. I would think that any "fixes" that the framework could provide, so that this works even when using old database versions, would be a huge bc break dealing with migrations.

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

7 participants