2016-11-16 103 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 

但请确保您的表上的列为空。