本文介绍了Laravel迁移:删除特定表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法/ laravel命令从生产服务器中删除特定表?

Is there any way/laravel-command to drop a specific table from the production server?

推荐答案

设置迁移

运行以下命令来设置迁移:

Run this command to set up a migration:

php artisan make:migration drop_my_table

然后您可以像这样构造迁移:

Then you can structure your migration like this:

<?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();
        });
    }
}

您当然可以放下而不检查是否存在:

You can of course just drop and not check for existence:

Schema::drop('my_table');

在此处进一步阅读文档:

Read further in the docs here:

这篇关于Laravel迁移:删除特定表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:54