Laravel 5.4 solves the error caused by too long special fields in migrations. laravelmigrations
Preface
This article mainly introduces the information about the migrations error reported by Laravel 5.4 due to the long special field. We will share the content for your reference. I will not talk much about it below. Let's take a look at the detailed introduction:
Laravel 5.4 has changed the default database character set. Now utf8mb4 includes support for storing emojis. MySQL requires v5.7.7 or later. When you try to run the migrations command on MariaDB or some old MySQL versions, you will encounter the following 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 `use rs_email_unique`(`email`)) [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
Solution
After query, we can set a default value in the boot method in the AppServiceProvider. php file:
<? Phpnamespace App \ Providers; use Illuminate \ Support \ ServiceProvider; // added code use Illuminate \ Support \ Facades \ Schema; class AppServiceProvider extends ServiceProvider {/*** Bootstrap any application services. ** @ return void */public function boot () {// added code Schema: defaultStringLength (191);}/*** Register any application services. ** @ return void */public function register (){//}}
Summary
The above is all the content of this article. There are still many shortcomings in this article. I hope this article will have some reference and learning value for everyone's learning or work. If you have any questions, please leave a message, thank you for your support.