I have this migration file
Schema::create(\'table_one\', function(Blueprint $table)
{
$table->increments(\'id\');
$table->string(\'name\');
1- Set a Rought:
Route::get('foreignkeyforimg', "foreignkey@index");
2- Create controller With Foreignkey Name.
3- Foreignkey Controller with extend from Migration class.
4- Go to database and delete old primary key manually from the table
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class Foreignkey extends Migration
{
function index(){
Schema::table('images', function (Blueprint $table) {
$table->foreign('sub_cat_id')
->references('id')
->on('subcategories')
->onDelete('cascade');
});
}
}