laravel migration drop foreign key code example

Example 1: larael drop foreign key

Schema::table('posts', function (Blueprint $table) {
	$table->dropForeign(['category_id']);
});

Example 2: laravel migration foreign key 5.6

Schema::table('posts', function (Blueprint $table) {
    $table->unsignedInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users');
});

Example 3: laravel remove foreign key

$table->dropForeign('posts_user_id_foreign');

Example 4: laravel drop foreign column

// Searched, laravel drop foreign column
Schema::table('users', function (Blueprint $table) {
    $table->dropColumn(['votes', 'avatar', 'location']);
});

Example 5: laravel migration drop foreign keys

$table->dropPrimary('users_id_primary');

Example 6: laravel migration drop foreign keys

$table->dropIndex(['state']); // Drops index 'geo_state_index'

Tags:

Misc Example