How to delete table in Laravel, how to drop table in migration, laravel migration delete table, how to rollback particular table in laravel, delete a table in laravel through migration

How to delete table in Laravel?

In this tutorial we will learn that how we can delete table in laravel. We can achieve this by two ways. They are following:-

1) Delete table from phpmyadmin

You can delete table direct from phpmyadmin. Remember to delete migrations also. if the migration is still there when you run the migration again the table will be created again.

laravel-migration-table
laravel-migration-table

2) Delete the migrations files from laravel

In second method drop all table from database. Next delete the migrations file of tables which you want to delete. After run the migration command again:-

php artisan migrate

3) Create a new migration to delete tables

Run the below command to create a new migration to delete tables:-


php artisan make:migration drop_duplicate_table

Now add the table name inside the up() function like below example:-




use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class DropDuplicateTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::dropIfExists('users');
        Schema::dropIfExists('users_role');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}

Run Below command to run migartion :-

php artisan migrate

Method 3 is the best way to delete a table in laravel through migration. Thanks for reading.

Post Created 130

Leave a Reply

Related Posts

Begin typing your search above and press enter to search. Press ESC to cancel.

Back To Top