migrate:rollback command reverts the last batch of database migrations that were run.
Syntax
Basic Usage
Rollback the last migration batch:How It Works
The rollback command:- Reads Migration History - Queries the
migrationstable to find the last batch number - Runs Down Methods - Executes the
down()method of each migration in reverse order - Removes Records - Deletes the migration records from the
migrationstable
Migration Batches
Migrations are organized into batches. Each time you runphp rawr migrate, all pending migrations are executed as a single batch. The migrate:rollback command reverts one batch at a time.
Example
Use Cases
Development Testing
Test your down() migration methods during development
Fix Migration Errors
Rollback and fix migrations that were deployed with errors
Database Reset
Combined with migrate, reset your database to a clean state
Schema Changes
Revert schema changes that cause issues
Best Practices
- Always implement
down()methods - Ensure all migrations can be rolled back - Test rollbacks locally - Verify your down() methods work before deploying
- Backup production data - Always backup before rolling back in production
- Use version control - Track migration files in git to coordinate with team
Common Workflow
See Also
migrate
Run pending migrations
migrate:status
Check migration status
make:migration
Create new migrations
Migration API
Migration class reference