Laravel Migrations - Dropping columns
The down
function is used for rollbacks, you have to add this dropColumn
in the up
function because it is an action you want to perform when running migrations.
So, in your up
function there should be:
Schema::table('clients', function (Blueprint $table) {
$table->dropColumn('UserDomainName');
});
And in the down
function you should do the inverse, add the column back:
Schema::table('clients', function (Blueprint $table) {
$table->string('UserDomainName');
});
This way, you can always return to any point in the migrations.
Comments
-
Black almost 2 years
I need to drop the column
UserDomainName
from my database tableclients
.At first I installed
doctrine/dbal
by executingcomposer require doctrine/dbal
followed bycomposer update
, like described in the documentation.Then I created the migration which I want to use to drop the column:
php artisan make:migration remove_user_domain_name_from_clients --table=clients
I added
Schema::dropColumn('UserDomainName');
to thedown()
method:<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class RemoveDomainName extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('clients', function (Blueprint $table) { // }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('clients', function (Blueprint $table) { Schema::dropColumn('UserDomainName'); }); } }
However, I get
Migrating: 2017_08_22_135145_remove_user_domain_name_from_clients Migrated: 2017_08_22_135145_remove_user_domain_name_from_clients
after executing
php artisan migrate
but no Column is dropped. If I execute it again I getNothing to migrate.