mysqllaravelphp-7.1laravel-5.5

Do Laravel migrations lock the tables they affect?


I'm using MySQL. The documentation doesn't say anything on the matter.

Let me know if there's anything else I can clarify. Thank you for your time.


Solution

  • It's now possible with Laravel 9 by using the command :

    php artisan migrate --isolated
    

    https://laravel.com/docs/10.x/migrations#running-migrations

    Isolating Migration Execution If you are deploying your application across multiple servers and running migrations as part of your deployment process, you likely do not want two servers attempting to migrate the database at the same time. To avoid this, you may use the isolated option when invoking the migrate command.

    When the isolated option is provided, Laravel will acquire an atomic lock using your application's cache driver before attempting to run your migrations. All other attempts to run the migrate command while that lock is held will not execute; however, the command will still exit with a successful exit status code:

    php artisan migrate --isolated