Execute a specific migration in Laravel 5.6

0

I need to run only migration within my laravel system, so as not to affect the rest of it.

Excerpt from migration:

public function up()
{
    Schema::create('notifications', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->text('body')->nullable();
        $table->timestamp('date');
        $table->timestamps();
    });
}

I have tried some procedures like those described here > but all to no avail. Always returning:

  

Nothing to migrate.

Note: The system has been updated and there are changes to be migrated

    
asked by anonymous 13.11.2018 / 16:52

2 answers

0

After much research and head banging I came up with a solution to run one or more specific migrations.

First you need to create a temporary folder that will be used to perform the migrations you need, in my case I called temp and created it in the path:

PROJECT_FOLDER/database/migrations

After this you need to copy the migrations you want into the temporary folder you just created. Then just run the following command in the root folder of your project, which will be in charge of executing them.

PROJECT_FOLDER> php artisan migrate --path="databse/migrations/temp"

Usage example

Folders:

PROJECT_FOLDER -
  -database
     -migrations
        migration_01.php
        migration_02.php 

Running processes (Linux) to execute only migration_02.php :

PROJECT_FOLDER> mkdir database/migations/temp
PROJECT_FOLDER> cp -rf database/migations/migration_02.php database/migations/temp
PROJECT_FOLDER> php artisan migrate --path="database/migrations/temp"

NOTE: Remembering that all the files that are inside your temporary folder will be migrated.

    
13.12.2018 / 20:31
0

When you run the php artisan:migrate command, Laravel reads your files into the database/migrations folder and then loads the classes and creates a record in the migrations table if the file has not yet been registered. So, if you've changed a migration that has already been run, you need the command php artisan migrate:rollback , to undo the migrations.

You can read more about this link: Database: Migrations

    
16.11.2018 / 14:34