khsing / laravel-world

provide countries, states, and cities relations and database.
MIT License
427 stars 89 forks source link

Illuminate\Database\QueryException ( Specified key was too long ) #44

Open mahdirashidi opened 3 years ago

mahdirashidi commented 3 years ago

php artisan world:init Execute migrate first, migrating... Migrating: 2017_04_08_163453_create_world_cities_locale_table Migrated: 2017_04_08_163453_create_world_cities_locale_table (80.40ms) Migrating: 2017_04_08_163453_create_world_cities_table

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 world_cities add index uniq _city(country_id, division_id, name))

at vendor\laravel\framework\src\Illuminate\Database\Connection.php:678 674▕ // If an exception occurs when attempting to run a query, we'll format the error 675▕ // message to include the bindings with SQL, which will make this exception a 676▕ // lot more helpful to the developer instead of just the database's errors. 677▕ catch (Exception $e) { ➜ 678▕ throw new QueryException( 679▕ $query, $this->prepareBindings($bindings), $e 680▕ ); 681▕ } 682▕

1) vendor\laravel\framework\src\Illuminate\Database\Connection.php:471 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes")

2) vendor\laravel\framework\src\Illuminate\Database\Connection.php:471 PDOStatement::execute()

gausoft commented 3 years ago

Hi, if you have created your database with utf8 general_ci collation, try this params :

'charset' => 'utf8',
'collation' => 'utf8_general_ci',

in config/database.php

gausoft commented 3 years ago

If not solved, try this solution https://blog.neversyn.com/how-to-fix-specified-key-was-too-long-issue/