how to drop a column in mysql laravel stackoverflow 1

how to drop a column in mysql laravel stackoverflow

 Class RemoveCommentViewCount extends Migration
  {
      public function up()
      {
          Schema::table('articles', function($table) {
             $table->dropColumn('comment_count');
             $table->dropColumn('view_count');
          });
      }

      public function down()
      {
          Schema::table('articles', function($table) {
             $table->integer('comment_count');
             $table->integer('view_count');
          });
      }
  }

Here is what the above code is Doing:
1. We’re creating a new migration file called RemoveCommentViewCount.
2. We’re using the Schema::table method to modify the articles table.
3. We’re using the dropColumn method to remove the comment_count and view_count columns.
4. We’re using the up method to run the migration.
5. We’re using the down method to rollback the migration.

Now, let’s run the migration:

php artisan migrate

Similar Posts