Search code examples
phpdatabaselaravelmigrationlaravel-5.3

Cannot drop column of existing table in Laravel 5.3?


I am having a problem in Laravel 5.3.

It won't allow me to drop a column from an existing table. I have run 'composer require doctrine/dbal' and that worked fine, but my column will not delete.

My add_column_to_table code:

<?php

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

class AddColumnToTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table)
        {
            $table->string('avatar')->default('default.pngs');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function ($table)
        {
            $table->dropColumn('avatar');
        });
    }
}

Thanks


Solution

  • To drop the column you need to rollback the migration in the following manner

    php artisan migrate:rollback