DEV Community

Osman Forhad
Osman Forhad

Posted on

How to remove a column from Laravel table using migration

I was working with Laravel framework and i create a laravel migration table and working with it but after some times i need to remove a column from my table and its should do using laravel migration. for that what was the process i deed. i want to share may knowledge with you.

for that the very first step was. i opened my terminal and navigate to project directory after that i was run below command on my terminal:

php artisan make:migration remove_categorrystatus_from_categories --table=categories

this command create a migration file for me and then i open this file and wrote my migration schema to remove a column from my database table. when i open the fle i saw there two function one is public function up and another is public function down.

To remove a column i updated those functions which is like bellow:
//the up function is
public function up()
{
Schema::table('categories', function (Blueprint $table) {
$table->dropColumn('categorrystatus');
});
}
//the down function is
public function down()
{
Schema::table('categories', function (Blueprint $table) {
$table->dropColumn('categorrystatus');
});
}

an then i go to my terminal and run below command:

php artisan migrate

which was remove the categorrystatus column from my catgories table
.
that's it. all are done
.
Happy Coding.
osman forhad

Top comments (0)