2016-11-16 101 views
0

我在Laravel 5.3中遇到問題。不能在Laravel 5.3中刪除現有表的列?

它不會允許我從現有表中刪除一列。我已經運行'作曲家需要教條/ dbal',並且工作正常,但我的專欄不會刪除。

我add_column_to_table代碼:

<?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'); 
     }); 
    } 
} 

感謝

+0

你看到了什麼錯誤 – user2693928

+0

請嘗試'removeColumn()'。 – Mihailo

+0

不知道這是否會有所作爲,但我認爲在添加(或修改)列時通常不會使用「藍圖」。 – jackel414

回答

1

要刪除您需要回滾以下方式遷移

php artisan migrate:rollback 
+0

啊是的,我遇到的問題是,我只是用'php artisan migrate' – Jay

0

嘗試此列:

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

您應該回滾您的遷移:

php artisan migrate:rollback 

但請確保您的表上的列爲空。