Ask Your Question
0

How to migrate particular file(s) from migrations using Laravel?

asked 2023-05-22 10:47:02 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-22 11:05:01 +0000

huitzilopochtli gravatar image

You can migrate a particular file by using the following command in your terminal:

php artisan migrate --path=/database/migrations/filename.php

Replace filename.php with the name of the migration file you want to migrate. This will run only the migration file you specified.

Alternatively, you can also specify the file name in the up() method of your migration file. For example:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamps();
    });

    // Add this line to run the migration file only when this method is called
    DB::statement(file_get_contents(__DIR__.'/filename.sql'));
}

In this case, the migration file filename.sql will only run when the up() method is called.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-22 10:47:02 +0000

Seen: 15 times

Last updated: May 22 '23