Voyager: Clean install 0.11 Syntax error or access violation: 1071 Specified key was too long; max key length is 767

Created on 17 Feb 2017  Â·  7Comments  Â·  Source: the-control-group/voyager

  • Laravel Version: 5.3.30
  • Voyager Version: 0.11
  • PHP Version: 7.0.11
  • Database Driver & Version: MSQL mariandb-10.1.9

Description:

  [Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
  oo long; max key length is 767 bytes (SQL: alter table `password_resets` ad
  d index `password_resets_email_index`(`email`))

  [Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
  oo long; max key length is 767 bytes

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

Steps To Reproduce:

php artisan voyager:install

Most helpful comment

This is a issue with the default length that Laravel uses and your database driver.

Open up you AppServiceProvider.php file and add the following:

use Illuminate\Support\Facades\Schema;

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

All 7 comments

This is a issue with the default length that Laravel uses and your database driver.

Open up you AppServiceProvider.php file and add the following:

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length
  is 1000 bytes (SQL: alter table `translations` add unique `translations_table_name_column_name_fore
  ign_key_locale_unique`(`table_name`, `column_name`, `foreign_key`, `locale`))

@zanjs, please try this

# i got this error too

AppServiceProvider.php ::

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
        Schema::defaultStringLength(191);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

when i type this cod in "cmd" ::
php artisan voyager:install

Got This Error ::

Publishing the Voyager assets, database, and config files
Copied Directory [\vendor\tcg\voyager\publishable\assets] To [\public\vendor\tcg\voyager\assets]
Copied Directory [\vendor\tcg\voyager\publishable\database\migrations] To [\database\migrations]
Copied Directory [\vendor\tcg\voyager\publishable\database\seeds] To [\database\seeds]
Copied Directory [\vendor\tcg\voyager\publishable\demo_content] To [\storage\app\public]
Publishing complete.
Publishing complete.
Migrating the database tables into your application
Migration table created successfully.


  [Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000
   bytes (SQL: alter table `translations` add unique `translations_table_name_column_name_foreign_key_locale
  _unique`(`table_name`, `column_name`, `foreign_key`, `locale`))



  [Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000
   bytes



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

i can to Fix it at this way !!

1.Don't Do this in "config/database.php"

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),



            'database' => 'laravel',
            'username' => 'root',
            'password' => '',


            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ]

take 'password , username ,database' in .env

2.(This is important) -> Edit create_translations_table.php at /migrations TO ->

Schema::create('translations', function (Blueprint $table) {
            $table->increments('id');

            $table->string('table_name')->unique();
            $table->string('column_name')->unique();
            $table->integer('foreign_key')->unsigned()->unique();
            $table->string('locale')->unique();

            $table->text('value');

//            $table->unique(['table_name', 'column_name', 'foreign_key', 'locale']);

            $table->timestamps();
        });

3. make a user in php my admin

4. set type to admin(into the user table)

you'll get this massage : Successfully installed Voyager! Enjoy 🎉

To help other Windows (WAMP) users who are getting stuck on the "php artisan voyager:install --with-dummy" command - I have already implemented the "Specified key was too long; max key length is ..." fix as suggested in the Docs (https://laravel-news.com/laravel-5-4-key-too-long-error) - There is a secondary error during initial migration that the Eric Barnes fix does not overcome.

To fix this...
I've added changed these three lines in my MySql's install folder, in the my.ini file:
default-storage-engine=INNODB
default_tmp_storage_engine=INNODB
innodb_large_prefix = 1

Assuming you now have an empty DB, the migrations should run successfully.

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IvanBohonosiuk picture IvanBohonosiuk  Â·  4Comments

ferrywae picture ferrywae  Â·  4Comments

abacram picture abacram  Â·  3Comments

winex01 picture winex01  Â·  3Comments

zzpwestlife picture zzpwestlife  Â·  3Comments