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');
});
}
}
Create the Migration To remove the columns you have to run the make migration command but instruct it as removing instead of creating a new migration. Make use of the "--table=your-table-name" flag and specify the table that you want to remove the columns.
The Laravel migrations will use the Schema facade to create and modify database tables and columns: Schema::create('tasks', function (Blueprint $table) { $table->bigIncrements('id'); $table->timestamps(); }); Inside the facade, you could specify the different columns that you want to add.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With