Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running one specific Laravel migration (single file)

I don't want to run All Outstanding Migrations on laravel 4. I have 5 migrations. Now I just want to run one migration. instead of doing : php artisan migrate I would like to run one specific migration like : php artisan migrate MY_MIGRATION_TO_RUN

like image 618
Mamadou Avatar asked Sep 30 '13 19:09

Mamadou


People also ask

How do I move a single file in Laravel 8?

Create MigrationOpen project into terminal and run this command. It will create a migration file with name like 2021_05_01_092040_create_products_table. php inside /database/migrations folder. Open migration file and write this complete code.

How do I run a specific migration in Rails?

To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.


1 Answers

Looks like you're doing it wrong.

Migrations were made to be executed by Laravel one by one, in the exact order they were created, so it can keep track of execution and order of execution. That way Laravel will be able to SAFELY rollback a batch of migrations, without risking breaking your database.

Giving the user the power to execute them manually, make it impossible to know (for sure) how to rollback changes in your database.

If your really need to execute something in your database, you better create a DDL script and manually execute it on your webserver.

Or just create a new migration and execute it using artisan.

EDIT:

If you need to run it first, you need to create it first.

If you just need to reorder them, rename the file to be the first. Migrations are created with a timestemp:

2013_01_20_221554_table 

To create a new migration before this one you can name it

2013_01_19_221554_myFirstMigration 
like image 133
Antonio Carlos Ribeiro Avatar answered Oct 06 '22 18:10

Antonio Carlos Ribeiro