When you are applying a foreign key using laravel migration it through this type of error
"Foreign key constraint is incorrectly formed"
The default structure of migration
User Table
---------
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
Chat Table
---------
Schema::create('chats', function (Blueprint $table) {
$table->id();
$table->integer('user_id');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
This is happening because Our column size should not exactly the same size, take a look below.
AND
How to Fix this issue
OR
Add unsignedBigInteger and your problem will be solved.