Software Development

What is the specific artisan command to run a single migration file in a Laravel project?

ST Asked by Steven Rogers · 08-05-2025
▲ 0 upvotes 16,939 views 0 comments
The question

I am working on a large-scale Laravel application with dozens of migration files. I recently created a new table but I don't want to run php artisan migrate because I have some pending changes in other migration files that aren't ready for production yet. Is there a way to point to a specific file path or use a flag to execute only one migration without triggering the entire batch in the migrations folder?

3 answers

▲ 0
KI
Answered on 10-05-2025

Laravel doesn't have a direct command like migrate:file, but you can achieve this by using the --path flag. You need to provide the relative path to your specific migration file starting from the base directory. The command would look like php artisan migrate --path=/database/migrations/your_migration_file_name.php. This tells the Artisan tool to ignore every other file in the directory and only focus on the one you've specified. This is a lifesaver when you are collaborating on a team and someone else has pushed unfinished schema changes to the main branch that you aren't ready to test yet.

▲ 0
JO
Answered on 12-05-2025

Kimberly’s method is the standard way to do it, but have you considered what happens if that specific migration depends on a foreign key in a table that hasn't been created by the other pending migrations yet?

BR 13-05-2025

Joshua, that is a critical point to raise! If there is a relational dependency, the migration will throw a SQL error. In that case, you have to manually ensure the parent table exists first. I usually recommend running a quick migrate:status before trying a targeted migration just to see the current state of the database and avoid those nasty constraint violations. It saves a lot of headache during the deployment phase.

▲ 0
HE
Answered on 14-05-2025

You can also just temporarily move the other migration files to a different folder, run the standard migrate command, and then move them back. It’s a bit "low-tech" but works perfectly every time.

ST 15-05-2025

I agree with Heather. While the path flag is the "official" way, sometimes moving files is faster if you have multiple specific ones to run that aren't in a neat alphabetical order.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Still have questions? Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Book Free Session

Book Free Session