Skip to main content

Laravel migration ' specified key was too long ' error

Error:

[Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

  [PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes


Solution:

if (mysql version < 5.7.7 )
{

add the following code to 'AppServiceProvider.php' file.

use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }

}

Comments

  1. It is what I was searching for is really informative. Laravel migration It is a significant and useful article for us. Thankful to you for sharing an article like this.

    ReplyDelete

Post a Comment

Popular posts from this blog

session_start(): Failed to initialize storage module: user (path: )

Error: session_start(): Failed to initialize storage module: user (path: ) Solution: When this error is given for the Codeigniter project you are running, that is specifically for not having a path recognised to store session data. Set config data as follows [file: your-project-folder/application/config/config.php] : $config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_save_path'] = APPPATH.'cache/'; $config['sess_match_ip'] = TRUE; $config['sess_time_to_update'] = 300; $config['sess_regenerate_destroy'] = FALSE;