Laravel Migration Error : Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes laravel 5.3

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

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

whats wrong? im using laravel 5.3

Refering to Laravel News and Laravel's migration guide:

As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:

use Illuminate\Support\Facades\Schema;

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

Laravel 5.4: Specified key was too long error, Laravel 5.4 made a change to the default database character set, and it's now utf8mb4 SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users As outlined in the Migrations guide to fix this all you have to do is edit your  Laravel Migration Error : Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes laravel 5.3.

open create_user_tabel and then write one line inside up function.
  Schema::defaultStringLength(191);
e.g

    public function up()
    {      
      Schema::defaultStringLength(191);

    Schema::create('users', function (Blueprint $table) {
                $table->increments('id');
                $table->string('name');
                $table->string('email')->unique();
                $table->string('password');
                $table->rememberToken();
                $table->timestamps();
    }

It will work 100%.

laravel/framework, Laravel Version: 5.6.26 PHP Version: 7.1.16 Database Driver & Version: MySQL the email column has a 255 character length which is greater than the limit 767 bytes. And he'll have to write migrations to fix all the things you just told him to do. Syntax error or access violation: 1071 Specified key was too long; max key​  Laravel 6 – 1071 Specified key was too long; max key length is 767 bytes Laravel 6 – 1071 Specified key was too long; max key length is 767 bytes

That error comes from the database basically..If you try to increase the length of that column by phpmyadmin, you will get the same error.

Syntax error or access violation: 1071 Specified key was too long, Hi, I've just upgraded to Laravel 5.4 and created my first project with it. Syntax error or access violation: 1071 Specified key was too long 1071 Specified key was too long; max key length is 1000 bytes (SQL: migration for the users table, and manually specifying the max-length of the email field, like so  Java Project Tutorial - Make Login and Register Form Step by Step Using NetBeans And MySQL Database - Duration: 3:43:32. 1BestCsharp blog Recommended for you

As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:

use Illuminate\Support\Facades\Schema;

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

After that everything should work as normal.

Specified key was too long; max key length is 767 bytes, Specified key was too long; max key length is 767 bytes [Illuminate\Databas Syntax error or access violation: 1071 Specified key was too long; max key length is From the docs https://laravel.com/docs/master/migrations#creating-indexes. The most concise screencasts for the working developer, updated daily. There's no shortage of content at Laracasts. In fact, you could watch nonstop for days upon days, and still not see everything!

In case, the above solutions or the official solution which is adding

Schema::defaultStringLength(191);

doesn't work. Try to edit the database.php file in config folder. Just edit

'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',

to

'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',

and it should work. Hope it helps.

Laravel 5.6 error: 1071 Specified key was too long, to the frustrating laravel 5.6 error "SQLSTATE[42000]: Syntax error or access violation Duration: 2:07 Posted: 24 Feb 2018 SQLSTATE [42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique ( email )) [PDOException] SQLSTATE [42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes.

Syntax error or access violation: 1071 Specified key was too long , laravel 5.6 migration problem..laravel migration problem.solved Syntax error or Duration: 4:46 Posted: 13 Aug 2018 For Laravel 5.4 you can find a solution in this Laravel 5.4: Specified key was too long error, Laravel News post: As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:

Laravel 5.4 migration: Specified key was too long error solution , MySQL reserves always the max amount for a UTF8 field which is 4 bytes so with COLLATE utf8mb4_unicode_ci; you are over the 767 max key length limit. Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

How to fix Laravel 5.4: Specified key was too long error, Three days ago Laravel 5.4 was released, so I have decided to give it a try. SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table If you are upgrading your application from Laravel 5.3, you are not required to switch to this character set. Arnold Schwarzenegger This Speech Broke The Internet AND Most Inspiring Speech- It Changed My Life. - Duration: 14:58. Andrew DC TV Recommended for you

Comments
  • Possible duplicate of Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
  • not work... this work in laravel 5.4 i try in laravel 5.3 i get the same error