How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Rollback a Specific Migration in Laravel
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Learn > Web Development > How to Rollback a Specific Migration in Laravel
Web Development

How to Rollback a Specific Migration in Laravel

how7o
By how7o
Last updated: April 22, 2026
8 Min Read
Laravel rollback specific migration — Artisan migrate:rollback --path command illustration
SHARE

A laravel rollback specific migration is a one-line Artisan command, but which flag you pick depends on what \”specific\” means: the single most recent migration, the last N batches, or exactly one file by path. Laravel 11 supports all three via migrate:rollback with --step and --path, and this guide walks through each variant, explains why the --path argument must be relative to the project root, and covers the migrate:fresh / migrate:refresh traps that destroy data if you run them without thinking.

Contents
  • TL;DR
  • Option 1 — Roll back by path: --path
  • Option 2 — Roll back the last batch: --step
  • Check before you roll: migrate:status
  • The migrate:refresh / migrate:fresh warning
  • What happens if down() is incomplete
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-21 on Laravel 11 with PHP 8.3. Originally published 2023-01-30, rewritten and updated 2026-04-21.

TL;DR

To roll back one specific migration file, pass its project-root-relative path: php artisan migrate:rollback --path=database/migrations/2022_08_31_165946_create_budget_entries_table.php. To roll back the most recent batch only, use php artisan migrate:rollback --step=1. Never use migrate:fresh in production — it drops every table.

Option 1 — Roll back by path: --path

When you want to revert exactly one file — because it’s the only one you’re iterating on, or because its batch contains other migrations you don’t want to touch — point Artisan at the file:

php artisan migrate:rollback --path=database/migrations/2022_08_31_165946_create_budget_entries_table.php

Laravel reads the file, runs its down() method, and removes the row from the migrations table. On Windows the path separator is a backslash: --path=database\migrations\2022_08_31_165946_create_budget_entries_table.php. Linux, macOS, and WSL all use the forward-slash form shown above.

The path must be relative to the project root. Laravel resolves --path against the application’s base path internally, so passing an absolute path like /var/www/myapp/database/migrations/... will not match any entry in Laravel’s migration registry and the command quietly does nothing. If a rollback “runs cleanly but nothing changed,” this is the first thing to check.

Option 2 — Roll back the last batch: --step

If you just ran php artisan migrate and immediately realized the new migration is wrong, --step=1 is the fastest undo:

php artisan migrate:rollback --step=1

This reverts the most recent migration batch — every file that was applied in the last migrate run, identified by the batch column in the migrations table. Increase the number to roll further back: --step=2 reverts the last two batches, --step=3 the last three, and so on.

Watch the batch granularity: if your last migrate applied five files at once, --step=1 reverts all five, not just the most recent one. Use migrate:status (below) to see the batch grouping before rolling back.

laravel rollback specific migration — migrate:rollback --path versus --step flow

Check before you roll: migrate:status

Before any rollback, run migrate:status to confirm what’s actually applied:

php artisan migrate:status

It prints a table with each migration file, a Ran? column (Yes/No), and a Batch column. This is the fastest way to spot that the file you’re about to target isn’t recorded as applied — in which case --path will silently no-op.

The migrate:refresh / migrate:fresh warning

Two adjacent commands look similar and do very different things:

# Rolls back EVERY migration in reverse, then re-runs them
php artisan migrate:refresh

# DROPS every table in the database, then re-runs every migration from scratch
php artisan migrate:fresh

Both destroy data. migrate:refresh at least calls each migration’s down() method, so you’d hope schema-level assumptions still hold. migrate:fresh skips down() entirely and calls SQL DROP TABLE on every table Laravel knows about — including ones from other developers’ in-flight migrations.

Neither belongs anywhere near production. Treat them as local-only dev tools for “my DB state drifted, I want a clean reset.” If you need to undo a single migration on production, stick to migrate:rollback --step=1 or --path.

What happens if down() is incomplete

Rollback only does what your migration’s down() method tells it to. If the up() method added a column and the down() method forgot to drop it, rollback leaves the column in place and removes the row from the migrations table — so the schema is inconsistent. This is a silent failure mode.

Always write symmetrical down() methods. For a column add via $table->string('code'), the down() should call $table->dropColumn('code'). For foreign keys, see adding foreign keys in Laravel migration — the drop order matters.

Frequently asked questions

What’s the simplest laravel rollback specific migration command?

php artisan migrate:rollback --step=1 reverts only the most recent migration batch. For a specific file, use php artisan migrate:rollback --path=database/migrations/2022_08_31_165946_create_budget_entries_table.php. The --path is relative to the project root — Laravel won’t accept an absolute path.

How does --step actually work?

--step=1 rolls back the last batch, --step=2 rolls back the last two batches, and so on. A “batch” is the group of migrations applied in a single php artisan migrate run, recorded in the migrations table’s batch column. If your last migrate applied five files at once, --step=1 reverts all five — not just one file.

Why does my --path rollback do nothing?

Two usual causes. First, you passed an absolute path (starting with /) instead of a project-root-relative one; Laravel looks it up against its migration registry and gets no match. Second, the file isn’t recorded in the migrations table as run — so there’s nothing to roll back. Check with php artisan migrate:status.

What’s the difference between migrate:refresh and migrate:fresh?

migrate:refresh rolls back every migration in reverse order and then re-runs them, preserving the structure of the process. migrate:fresh drops every table in the database and re-runs migrations from scratch. Both destroy data. Never run migrate:fresh against production — it’s a dev-only tool.

How do I see which migrations have been run?

php artisan migrate:status prints a table of every migration file and whether it’s been applied (Ran? column) and in which batch. It’s the fastest way to confirm the state before running a rollback — especially on a shared dev DB where you didn’t run the last migrate yourself.

Related guides

  • How to Install Laravel on Ubuntu — set up Laravel 11 and Artisan before touching migrations.
  • How to Add Foreign Keys in Laravel Migration — write the foreign-key pair your down() needs to drop cleanly.
  • How to Add New Columns to an Existing Table in Laravel Migration — the symmetrical up/down pattern for schema additions.
  • Change a MySQL Column Data Type Using Migration in Laravel — rollback-friendly column type changes.

References

Official Laravel migrations docs (rollback, refresh, fresh, status): laravel.com/docs/migrations.

TAGGED:BashLaravelmigrationmysqlphp

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Laravel left outer join — query builder leftJoin illustration with two tables How to Do a Left Outer Join in Laravel Query Builder
Next Article Laravel nullable exists validation — nullable, sometimes, and present rule combinations Laravel Nullable Exists Validation (nullable, sometimes, present)
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

Automatic logout timeout for command line in Ubuntu (TMOUT 300s)
Server Management

Automatic Logout Timeout for Command Line in Ubuntu (TMOUT 300s)

5 Min Read
Laravel last inserted ID — Eloquent save populates model primary key illustration
Web Development

How to Retrieve the Last Inserted ID in Laravel Eloquent

8 Min Read
WordPress search users by multiple fields — WP_User_Query search_columns + meta_query
Web Development

How to Search Users by Multiple Fields in WordPress

7 Min Read
Laravel run project from GitHub — git clone through artisan serve pipeline
Web Development

How to Run a Laravel Project from GitHub

8 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?