user image

Jo Micheal
Published in : 2022-01-20

[solved] SQLSTATE[42000]: Syntax error or access violation

Laravel

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') )

I get this error when i try to run the migration using 

php artisan migrate

what should I do to figure out this Error?

web-brackets.com

Comments

Joseph Morgan Date : 2022-01-20

Best answers

11

Best answers

11

that's because the defaultStringLength is not setup, you need to limit it from /app/Providers/AppServiceProvider.php
using the Schema 

so the file should looks like 

<?phpnamespace App\Providers;use Illuminate\Support\ServiceProvider;use Illuminate\Support\Facades\Schema;class AppServiceProvider extends ServiceProvider{ /** * Register any application services. * * @return void */ public function register(){ // } /** * Bootstrap any application services. * * @return void */ public function boot(){ // Schema::defaultStringLength(191); }}

I imported the schema using use Illuminate\Support\Facades\Schema;
then added Schema::defaultStringLength(191); into the boot function
Let me know if this worked with you

Jo Micheal Date : 2022-01-20

Thanks, this was the issue, when i updated the file like this it worked fine 

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

How to check Laravel version?
Publish date: 2022-04-07 | Comments: 2
Undefined Variable problem on Laravel 9.x
Publish date: 2022-03-06 | Comments: 3