2016-05-16 19 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

あなたはscpecific表を削除するためのコマンドがあるかどうかを確認するためにphp artisan migrate:rollback --helpを使用することができます。

は、ここに私の出力です: enter image description here

あなたが特定のテーブルをドロップするlaravelにはオプションはありません見ることができるように。未だに。 CMIW。手動で削除するか、phpmyadminを使用して削除することもできます。それが叶うことを願っています

関連する問題