I study Laravel. I create a migration, enter the fields that need to be created. Then I start migrations, errors come out, the table does not create. What is the problem? DB is created. Openserver. enter image description here

<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateArticlesTable6 extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('articles', function (Blueprint $table) { $table->increments('id'); // id INT auto_increment PRIMARY KEY $table->string('name',100); //Varchar, 100 $table->text('text'); //text $table->string('img',255); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('articles'); } } 
  • In my opinion, the problem is in migrating with users (what is written in the error), and not with articles. - neluzhin

1 answer 1

I suspect that laravel 5.4 is using utf8mb4 as the default encoding, respectively, if you have a mysql version below 5.7.7 or change the default string length in AppServiceProvider

  use Illuminate\Support\Facades\Schema; /** * Bootstrap any application services. * * @return void */ public function boot() { Schema::defaultStringLength(191); } 

or this one

but I did not use it

You can also look at laravel-news

  • Yes, Laravel 5.4. You can explain to the noob a little more detail how it is done and where to prescribe what is needed in App \ Providers this: <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // } /** * Register any application services. * * @return void */ public function register() { // } } <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // } /** * Register any application services. * * @return void */ public function register() { // } } <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // } /** * Register any application services. * * @return void */ public function register() { // } } and c - Djonson
  • @Djonson And what is not clear? Go to the class App \ Providers \ AppServiceProvider.php, connect the class Illuminate \ Support \ Facades \ Schema, if there is no boot () method, copy what you gave above and that's it. - Orange_shadow
  • It turned out, thanks. I can not understand how to thank for the answer, tell me a noob. - Djonson
  • mark the answer as the right decision - varz62
  • how to do it? I can't find anywhere else - Djonson