laravel 如何从迁移中的表中删除 softDeletes

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37532131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:54:25  来源:igfitidea点击:

How to drop softDeletes from a table in a migration

phpdatabaselaravellaravel-migrations

提问by miken32

I'm adding the soft delete columns to my table in a migration:

我在迁移中将软删除列添加到我的表中:

public function up()
{
    Schema::table("users", function ($table) {
        $table->softDeletes();
    });
}

But, how can I remove these in my down()function, if I roll back the migration? Is there a built-in method to do this, or do I just manually delete the columns that get added?

但是,down()如果我回滚迁移,如何在我的函数中删除这些?是否有内置方法可以执行此操作,还是我只是手动删除添加的列?

回答by álvaro Guimar?es

On your migration class:

在您的迁移课程中:

public function down()
{
    Schema::table("users", function ($table) {
        $table->dropSoftDeletes();
    });
}

Illuminate\Database\Schema\Blueprint.php:

Illuminate\Database\Schema\Blueprint.php:

public function dropSoftDeletes()
{
    $this->dropColumn('deleted_at');
}

Since Laravel 5.5, this information can be found in the documentation.

从 Laravel 5.5 开始,可以在文档中找到这些信息。