2016-05-16 94 views

回答

5

設置遷移。

運行此命令設置遷移:

php artisan make:migration drop_my_table 

然後你就可以構建這樣的遷移:

<?php 

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

class DropMyTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     // drop the table 
     Schema::dropIfExists('my_table'); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     // create the table 
     Schema::create('my_table', function (Blueprint $table) { 
      $table->increments('id'); 
      // .. other columns 
      $table->timestamps(); 
     }); 
    } 
} 

當然,你可以只下降並不會檢查是否存在:

Schema::drop('my_table'); 

請閱讀文檔中的進一步說明:

https://laravel.com/docs/5.2/migrations#writing-migrations

您可能還需要考慮刪除任何現有的外鍵/索引,例如,如果你想刪除主鍵:

public function up() 
{ 
    Schema::table('my_table', function ($table) { 
     $table->dropPrimary('my_table_id_primary'); 
    }); 

    Schema::dropIfExists('my_table'); 
} 

更多的文檔中刪除索引等在這裏:

https://laravel.com/docs/5.2/migrations#dropping-indexes

+1

這就像一個魅力!,謝謝! –

0

可以使用php artisan migrate:rollback --help,看看是否有是一個命令刪除scpecific表。

這裏是我的輸出: enter image description here

你可以看到有在laravel沒有選擇放棄特定表。還沒。 CMIW。另一個出路是手動刪除它們或使用phpmyadmin。希望它有幫助