0

[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

AppServiceProvider.php this way did not worked I can not fix this error any way to fix it?

use Illuminate\Support\Facades\Schema;

public function boot() 
{
    Schema::`defaultStringLength`(191); 
}
NarendraR
  • 6,770
  • 7
  • 35
  • 69
Ezatla
  • 65
  • 7

2 Answers2

1

Change

use Illuminate\Support\Facades\Schema;

to

use Schema;
Sandeesh
  • 9,590
  • 2
  • 24
  • 37
1

This happens to me when I tried to install voyager. After few digging I found these two answers which working.

Solution 01

* /config/database.php *

'mysql' => [
    ...,
    ...,
    'engine' => 'InnoDB',
 ] 

Solution 02
editing the database.php file in config folder.(Same file in above answer) Just edit,

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

to

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

I found these from Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes issue answers. So all credit should go to @dexterb and @Koushik Das

vimuth
  • 2,928
  • 13
  • 43
  • 73