Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Radi
Created February 29, 2020 20:39
Show Gist options
  • Save Ahmed-Radi/8a8e5dc840355855fa61489c4828a37a to your computer and use it in GitHub Desktop.
Save Ahmed-Radi/8a8e5dc840355855fa61489c4828a37a to your computer and use it in GitHub Desktop.
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table `project`.`#sql-3c44_2f` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `comments` add constraint `comments_com_post_foreign` foreign key (`com_post`) references `posts` (`post_id`) on delete cascade)
at E:\xampp\htdocs\laravel\Laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `project`.`#sql-3c44_2f` (errno: 150 "Foreign key constraint is incorrectly formed")")
E:\xampp\htdocs\laravel\Laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
2 PDOStatement::execute()
E:\xampp\htdocs\laravel\Laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
Please use the argument -v to see more details.
@Ahmed-Radi
Copy link
Author

To Solve This problem

Just Add unsigned();
Look to this example
If you Want add foreign key to this

   $table->bigInteger('com_user');

Just Add unsigned()

   $table->bigInteger('com_user')->unsigned();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment