I need to drop a column from a table on a Laravel migration.
The usual code to do it is:
$table->dropColumn([ 'city', 'country' ]);
But you have to install Doctrine DBAL
package to use dropColumn()
method.
Looking for another solution, I have found removeColumn()
method (http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html#method_removeColumn):
$table->removeColumn('city');
$table->removeColumn('country');
But not seem to work. It does nothing, no fails and leaves intact columns.
What is the difference between removeColumn and dropColumn methods?
Which is the use of removeColumn() method?
Show activity on this post. This way a new migration file will be created. Set your column details there, run the migrations using php artisan migrate and that's all. You'll have this new column in your users table without losing previously stored data.
The method removeColumn()
is actually pretty useless for most migrations. It just removes the column from the blueprint and not actually 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 would not contain the column foo
because it is removed from the schema.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With