How to drop softDeletes from a table in a migration

25,426

On your migration class:

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

Illuminate\Database\Schema\Blueprint.php:

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

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

Share:
25,426

Related videos on Youtube

miken32
Author by

miken32

Programmer since (in a manner of speaking) 1988, systems and network administrator, open source contributor, old guy. He/him.

Updated on July 09, 2022

Comments

  • miken32
    miken32 almost 2 years

    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?

  • miken32
    miken32 almost 8 years
    Thanks; is there any actual API documentation that you used to find this? I'm using the docs at laravel.com/docs/5.2 which gives a good overview, but doesn't list every available method.
  • Álvaro Guimarães
    Álvaro Guimarães almost 8 years
    You better navigate through the core classes. The documentation is always lacking some sugar.
  • Yevgeniy Afanasyev
    Yevgeniy Afanasyev over 7 years
    OMG, after dropSoftDeletes - we are going to have a mess of historical and actual records together...
  • Jquestions
    Jquestions over 5 years
    Updating Laravel framework files is not a good move?! What about updates, etc?
  • Elijah Lofgren
    Elijah Lofgren over 3 years
    dropSoftDeletes() already exists in Illuminate\Database\Schema\Blueprint.php (at least as of Laravel 8.12) so no updating of framework files is necessary.
  • Álvaro Guimarães
    Álvaro Guimarães over 3 years
    They were always there, just not in the docs. And I never suggested editing framework files, please don't do it @Jquestions