Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davy_yg's avatar
Level 27

Personal Access Tokens migration error

I get this error message. Any clue why?

[agribisc@jkt09 public_html]$ php artisan migrate

INFO Running migrations.

2019_12_14_000001_create_personal_access_tokens_table ............................................... 11ms FAIL

Illuminate\Database\QueryException

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes(Connection: mysql, SQL: alter table personal_access_tokens add index personal_access_tokens_tokenable_type_tokenable_id_index(tokenable_type, tokenable_id))

0 likes
1 reply
LaryAI's avatar
Level 58

The error you're encountering is related to the maximum key length in MySQL. By default, MySQL has a limit on the size of index keys, and this can be exceeded when using certain character sets like utf8mb4, which uses more bytes per character.

To resolve this issue, you can adjust the default string length for your database schema in Laravel. Here's how you can do it:

  1. Update the AppServiceProvider:

    Open the AppServiceProvider located in app/Providers/AppServiceProvider.php. In the boot method, set a default string length for your database schema using the Schema facade.

    use Illuminate\Support\Facades\Schema;
    
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
    
  2. Ensure the AppServiceProvider is loaded:

    Make sure that the AppServiceProvider is registered in your config/app.php file under the providers array. This is usually done by default in Laravel applications.

  3. Run the migration again:

    After making these changes, try running your migrations again with:

    php artisan migrate
    

This should resolve the issue by ensuring that the length of indexed string columns does not exceed the MySQL limit. The 191 length is a common workaround for this issue when using utf8mb4, as it ensures that the index length stays within the 767-byte limit for InnoDB tables.

Please or to participate in this conversation.