Run a specific Migration on Laravel 5.6

Asked

Viewed 5,245 times

2

I’m in need of executing only one migration within my system laravel, not to affect the rest of it.

Excerpt from the 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’ve tried some procedures like the ones described here but all without success. Always returning:

Nothing to migrate.

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

3 answers

2


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

First you need to create a temporary folder that will be used to run the Migrations you need, in my case called temp and created on the way:

PROJECT_FOLDER/database/migrations

After that 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 he will take care of running them.

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

Example of use

Folders:

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

Running processes (Linux) to run 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 files that are inside your temporary folder will be migrated.

2

If you have access to the database, just access the table migrations and delete the record from the table. Then execute the command php artisan migrate again.

0

When you execute the command php artisan:migrate Laravel reads your files inside the folder database/migrations and then load the classes and create record in the table migrations if the file has not yet been registered. Thus, if you have changed a Migration that has already been executed, you need the command php artisan migrate:rollback, to undo the Migrations.

You can read more about this link: Database: Migrations

  • I have already carried out all these steps and without success, I believe that an alternative solution to this will be necessary

Browser other questions tagged

You are not signed in. Login or sign up in order to post.