What is the difference between removeColumn and dropColumn methods on Laravel Framework?

I need to remove a column from a table when migrating Laravel.

The usual code for this:

$table->dropColumn([ 'city', 'country' ]);

      

But you need to install the package Doctrine DBAL

to use the method dropColumn()

.

Looking for another solution, I found a method removeColumn()

( http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html#method_removeColumn ):

$table->removeColumn('city'); 
$table->removeColumn('country');

      

But doesn't seem to work. It doesn't do anything, doesn't fail, and leaves entire columns.

What is the difference between the removeColumn and dropColumn methods?

What is the use of the removeColumn () method?

+3


source to share


1 answer


The method removeColumn()

is actually useless for most migrations. It just removes the column from the plan, not from the database. So, if you had this migration:

Schema::create('foo', function (Blueprint $table) {
    $table->increments('id');
    $table->timestamps();

    $table->string('foo')->nullable();
    $table->string('bar');

    $table->removeColumn('foo');
});

      



The created table will not contain the column foo

because it is being removed from the schema.

+6


source







All Articles