Skip to content
Advertisement

Laravel/MariaDB: errno 150 “Foreign key constraint is incorrectly formed”

I’m on Laravel 5.4, PHP 5.6, Ubuntu 18.04, MariaDB 10.4.8. When I run php artisan migrate, I get:

I’m trying to use https://github.com/klisl/laravel-comments. Before trying to perform a migration with this package I had created DB at phpMyAdmin, had configured .env by adding DB name and stuff, had successfully run php artisan migrate, php artisan make:auth and php artisan make:controller AuthController. Then, after running php artisan vendor:publish --provider="KlislCommentsCommentsServiceProvider" I get 2 new files in migrations folder: date_number_CreateCommentsTable.php and date_number_ChangeCommentsTable.php

Here’s source from these 2 files:

CreateCommentsTable.php:

ChangeCommentsTable.php:

So then I run php artisan migrate and get the error I’ve written about above.

I’ve already tried adding ->unsigned() at CreateCommentsTable. Also I’ve tried to put the foreign keys out of the function at ChangeCommentsTable like this:

and this:

As any of didn’t work out, I decided to post the default version of source above. If you help me with this, you really save my day c:

UPD: Here’s source from CommentController.php:

Advertisement

Answer

I haven’t had posts table so the problem was solved by adding it. I’ll mark this answer as a correct when it’s possible.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement