Laravel 5.8 solving first time migrations errors

Chrisostom Kaweza
Apr 23 · 2 min read

In creating one of my laravel project i come across errors during migration. I think most laravel beginners might struggle to solve them, that is why i decided to create this article.

Let us look at the errors:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long.

Why error?

You will receive this error in laravel 5.4 and above because laravel upgraded to utf8mb4 database character set, which include support for storing emojis.If you are running MySQL 5.7 and higher you will likely not receive this errors.


add line 6 and line 28 of the code above to solve the problem

SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘users’ already exists

Why error?

As the error is explicit, the table “users” already exist in our database this can be because of two reason. One, the table really exist in database,second composer already generated migration class files in autoload_classmap.php.


case one : delete the particular table in your database.

Case two: run composer dump-autoload this command will regenerate classes needed to be included in a project including migration classes.

Hint: In most case you have two do step one and step two

You may also use command php artisan migrate:fresh which basically drop all tables and run migration again.

Many things may go wrong including the errors that i have not mention above. Any way hope it help some one.

If you like the article please give a clap,for any query corresponding the article put them in section comment below,otherwise you can email me,check me twitter here,LinkedIn here .

Happy to give back to developers community.


Chrisostom Kaweza

Written by

Web Back-end guy