简体   繁体   中英

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

要删除该列,您需要按以下方式回滚迁移

php artisan migrate:rollback

Try this:

public function down()
{
    Schema::table('users', function (Blueprint $table)
    {
        $table->dropColumn('avatar');
     });
    }
}

You should rollback your migration:

php artisan migrate:rollback

But make sure that column is empty on your table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM