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

PeregrineStudios's avatar

How can I make `php artisan migrate` a 'blocking' error?

Right now, I'm running an automated Codeship deployment of a Laravel project. As part of the build/test phase, we create a temporary testing database and run the migrations to ensure they all run correctly.

One problem: when php artisan migrate fails, it doesn't seem to return a 'hard error', that would block the rest of the script from running. Instead, it gets treated as normal output, and the script continues on its merry, possibly pushing broken migrations to a staging server.

Is there a way to make php artisan migrate errors stop the rest of the script from running?

0 likes
4 replies
PeregrineStudios's avatar

Hm, I haven't tried that - I'm not sure how to check if the migration completed successfully or not, to then call exit or not. I'll give it a try and see if that does the trick.

PeregrineStudios's avatar

Interestingly, the CodeShip build step doesn't seem to fail on a return status 1. So I had to implement it like this:

# Run Laravel migrations on the test database.
php artisan migrate --force

# Force exit if the migrations fail.
if [ $? = 1 ]; then
    exit
fi

In other words, manually checking if the exit code was 1, and exiting if it was.

hassaans2008's avatar

Hope the following blog will help you with the solution to go with: medium.com/p/c6ab005fd928

Please or to participate in this conversation.