2016-05-16 104 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。希望它有帮助