Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raphael's avatar

Prevent migrations from being run automatically

Laravel 6.5:

Whenever I enter artisan make:migration ..., a migration file is being created and automatically run. After pressing enter, the command seems to wait for a short amount of time (like 5-10 seconds) to let me add some database instructions into the migration. But of course this short period is way too little. This results in a processed migration without any operations. Then I have to remove the entry from the migrations-table, finish the migration and run artisan migrate on my own.

So I always have to cancel the make:migration command with CTRL+C to prevent it from being run automatically.

This phenomenon happens to all my co-workers who are working on the same project.

Is there a better way? Can I disable the automatic migrations somewhere in the config? I did not find anything in the documentation.

0 likes
8 replies
ismaile's avatar

Can you check if you have something related to migrate in your schedule method in App\Console\Kernel.php ?

Besides, please perform a search in all your code for something like:

call('migrate')

or

command('migrate')

These are just some ideas. These might give you a clue about where this behaviour comes from.

JeromeFitzpatrick's avatar

@raphael check also that you do not have a migration running in the constructor of a command. When you run an artisan command, it instantiates the classes of the other commands and whatever is in the constructor will be executed.

raphael's avatar

Thanks. I found out that it has to to with my composer.json-file that has these lines:

"scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi",
            "php artisan migrate --force",
            "php artisan db:seed --force",
            "php artisan queue:restart"
        ],
        ...

If I remove the line "php artisan migrate --force" the auto-migration does not happen.

What's strange is that if change the line to "php artisan aisghjsagdjasdgalsdg" (that command does not exist) no error is given after running artisan make:migration .... When I run composer install however, the executions fails naming that this command does not exist.

I added another line into the post-autoload-dump-array: touch test.txt And yes, a test.txt-file was created after making a new migration.

That means the make:migration-command is running those scripts in the composer-file and ignores any error that might occur.

We do not want to remove them due to development and deployment purposes.

How can I prevent make:migration from running these commands?

Snapey's avatar

So wait, you are saying that you WANT a setup where someone could accidentally blow away the entire production database because they ran composer dump ?

1 like
raphael's avatar

Okay, I'll find a better way to migrate, seed and queue-restart with only one command.

Thanks everyone!

ismaile's avatar
ismaile
Best Answer
Level 30

If your requirement is to run 'migrate', 'db:seed' and 'queue:restart' with one command, I can think of 2 choices:

  • Putting your commands one after another in a .sh file (let's call it populate.sh):
#!/bin/bash

cd ~/path/to/myproject

php artisan migrate --force
php artisan db:seed --force
php artisan queue:restart

In this case, please make sure you specify the right ~/path/to/myproject Then, run chmod +x populate.sh to make your file executable. Then you can run it with ./populate.sh if you are in the directory where populate.sh is.

  • Create a command by running php artisan make:command MyCommand where MyCommand is the name of your command class. Then you would have to open this file, modify the signature and description (the signature value will be used when running the command as follows php artisan mysignature). Then, finally you would have to write your code in the handle method. It should be something like this based on your set of commands:
        $this->call('migrate', ['--force' => true]);
        $this->call('db:seed', ['--force' => true]);
        $this->call('queue:restart');

Hope this helps

1 like
raphael's avatar

ismaile, thanks a lot!

That's actually a good idea to have a custom artisan command that combines this individual stuff.

1 like

Please or to participate in this conversation.