CharliePrynn
CharliePrynn

Reputation: 3080

Laravel 4 Artisan drop existing column from table

I created a migration script that creates a table called Archives.

It has 4 columns not including timestamps/increments. The tables columns are name, title, content and image.

I need to drop the image column as it is no longer needed.

I have not been able to find a way to do this by searching and was hoping someone could give me the best way to do this.

I attempted to accomplish this by creating a new migration and then running

php artisan migrate:rollback --pretend

But this tries to roll back the previous migration.

class DropImageColumnArchive extends Migration
{

    /**
     * Run the migrations.
     * @return void
     */
    public function up()
    {
        Schema::table('archives', function ($table) {
            $table->text('image');
        });
    }

    /**
     * Reverse the migrations.
     * @return void
     */
    public function down()
    {
        Schema::table('archives', function ($table) {
            $table->drop_column('image');
        });
    }
}

Upvotes: 5

Views: 8467

Answers (1)

Jonny C
Jonny C

Reputation: 1941

Almost there change drop_column to dropColumn

Referenced Here http://laravel.com/docs/schema#renaming-columns

Schema::table('users', function($table)
{
    $table->dropColumn('votes');
});

Edit Referenced here for 5.1 http://laravel.com/docs/5.1/migrations

Upvotes: 18

Related Questions