zachleigh / laravel-property-bag

Add settings to any Laravel model.
MIT License
83 stars 8 forks source link

error : Specified key was too long; max key length is 1000 bytes #24

Closed AMAFsoft closed 5 years ago

AMAFsoft commented 5 years ago

i'm getting this error after running php artisan migrate

full error :

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 'property_bag' add unique 'property_bag_resource_type_resource_id_key_unique'('resource_type', 'resource_id', 'key'))

  at /vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes")
     /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:119

  2   PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes")
      /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117
AMAFsoft commented 5 years ago

I've commented this line : // $table->unique(['resource_type', 'resource_id', 'key']);

and it works for now.

zachleigh commented 5 years ago

The combination of your resource_type, resource_id and key are just too long. You can probably change the default to something that works better for you: https://laravel-news.com/laravel-5-4-key-too-long-error