-2

I am new in Laravel and i am using "Laravel version 9" (latest),I run following command but giving me following error

Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

i had 4 files inside "database/migrations" then i run "php artisan serve" command but only "two tables" inserted into database (users(empty) and migrations),how can i add rest of tables ? I tried with following code inside "/app/Providers/AppServiceProvider.php" but still getting same error,How can i fix this ?

public function boot()
{
    Schema::defaultStringLength(191);
}
sammy
  • 13
  • 1
  • 1
    please share your migration code, i believe the 3rd one that trigger this error – Win Jan 23 '23 at 06:03
  • Did you ran php artisan config:cache command after adding this lie into AppServiceProvider ? – Khalid Khan Jan 23 '23 at 06:04
  • 2
    `php artisan serve` doesn't run any pending migrations. It instead starts up PHP's built-in web server. – steven7mwesigwa Jan 23 '23 at 06:05
  • How long are your keys leading to the issue/error? *Increasing* the default String length to a higher value than `191` would probably be sufficient to resolve your issue. – steven7mwesigwa Jan 23 '23 at 06:09
  • 3
    Does this answer your question? [Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes](https://stackoverflow.com/questions/42244541/laravel-migration-error-syntax-error-or-access-violation-1071-specified-key-wa) – steven7mwesigwa Jan 23 '23 at 06:13
  • 1
    Once you run php artisan migrate do you get an errors ? If not can you check the storage/logs/laravel.log ? Do you see any errors there. Can you share one of the migration files – maximus 69 Jan 23 '23 at 06:20
  • 1
    you need to re-run migration. ``php artisan migrate:fresh`` – tirta keniten Jan 23 '23 at 08:02

1 Answers1

0

In your file config/database.php, find key mysql and add line

'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',

Should look something like this :

    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'modes' => [
            'ONLY_FULL_GROUP_BY',
            'STRICT_TRANS_TABLES',
            'NO_ZERO_IN_DATE',
            'NO_ZERO_DATE',
            'ERROR_FOR_DIVISION_BY_ZERO',
            'NO_AUTO_CREATE_USER',
            'NO_ENGINE_SUBSTITUTION'
        ],
        'engine' => 'InnoDB ROW_FORMAT=DYNAMIC', // this line
    ],
StewieSWS
  • 546
  • 3
  • 10