【发布时间】:2016-09-11 23:11:46
【问题描述】:
有什么方法/laravel-command 可以从生产服务器中删除特定的表吗?
【问题讨论】:
标签: laravel database-migration
有什么方法/laravel-command 可以从生产服务器中删除特定的表吗?
【问题讨论】:
标签: laravel database-migration
设置迁移。
运行此命令以设置迁移:
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');
}
更多关于删除索引等的文档:
【讨论】: