Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.4 Specific Table Migration

Hi read all the included documentation here in https://laravel.com/docs/5.4/migrations.

Is there a way on how to migrate a certain migration file (1 migration only), cause right now every time there is a change I use php artisan migrate:refresh and all fields are getting reset.

like image 907
Martney Acha Avatar asked Aug 03 '17 02:08

Martney Acha


People also ask

How do I migrate a specific migration file in Laravel?

To run the specific migration in Laravel, you need to use --path option with the php artisan migrate command. Let's take a simple example, we have '2019_12_04_131405_create_payments_table. php' migration in the database/migrations directory and we would like to run this migration.

How do I refresh a specific table in Laravel?

If you want to empty all table's data from database then runphp artisan migrate:refresh command.


2 Answers

First you should create one migration file for your table like:

public function up()     {         Schema::create('test', function (Blueprint $table) {             $table->increments('id');             $table->string('fname',255);             $table->string('lname',255);             $table->rememberToken();             $table->timestamps();         });     } 

After create test folder in migrations folder then newly created migration moved/copied in test folder and run below command in your terminal/cmd like:

php artisan migrate --path=/database/migrations/test/ 
like image 82
AddWeb Solution Pvt Ltd Avatar answered Sep 21 '22 18:09

AddWeb Solution Pvt Ltd


you should add the path to your migration file to refresh just this table and run

php artisan migrate:refresh --path=/database/migrations/fileName.php 
like image 22
Wissem SASSI Avatar answered Sep 21 '22 18:09

Wissem SASSI