Revert Migrations in Laravel
- Posted on
- Laravel
- By Deepak Talwar
A series of commands called Laravel Migration
These modifications could involve building new tables, changing current tables, adding or changing columns, and seeding the database with starting data.
In a migration class, you will find two methods: up and down. To expand your database with new tables, columns, or indexes, you can use the up method, and to undo the changes made by the up method, you can use the down method.

Migration specifies the modifications you wish to apply to your database structure.
Setting Migration Connection
To communicate with a database connection different than your application's default, set the connection property of your migration:
protected $connection = 'pgsql';
public function up(): void{ // ... }
Squash migration - Your application may require more migrations as you build it. This can cause your database/migrations directory to become cluttered with hundreds of migrations. You can "squash" migrations into one SQL file. Start by running dump.
php artisan schema:dump
# Automatically clean up old files
php artisan schema:dump --prune# Specify the connection name
php artisan schema:dump --database=cms
The new file mysql-schema.sql is under /database/schema. This provides the schema for all migrations thus far. This script speeds up testing and CI for existing projects by removing unnecessary migrations.
Rollback /Reversing migrations Laravel has a built-in Artisan migrate tool for reversing schema changes after migration failures.
Revert the last batch of migrations:
php artisan migrate:rollback
Will revert the last batch of migrations applied to your database.Revert a specific number of steps
php artisan migrate:rollback --step=1
Will only roll back the most recent migration file.Rolling back to a specific point in time:
php artisan migrate:rollback --date="2025-01-01 12:00:00"
Will roll back all migrations that were executed after the specified date.
Database verification after rollback
Check the database schema and data after rolling back migrations to assure success.
php artisan migrate:status
s